title: Iphone 6 camera calibration for OpenCV
body: <p>Im developing an iOS Augmented Reality application using OpenCV. I'm having issues creating the camera projection matrix to allow the OpenGL overlay to map directly on top of the marker. I feel this is due to my iPhone 6 camera not being correctly calibrated to the application. I know there is OpenCV code to calibrate webcams etc using the chess board, but I can't find a way to calibrate my embedded iPhone camera. </p>
  
  <p>Is there a way? Or are there known estimate values for iPhone 6? Which include: focal length in x and y, primary point in x and y, along with the distortion coefficient matrix.</p>
  
  <p>Any help will be appreciated. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Deduced values are as follows (using iPhone 6, camera feed resolution 1280x720):</p>
  
  <pre><code>fx=1229
  cx=360
  fy=1153
  cy=640
  </code></pre>
  
  <p>This code provides an accurate estimate for the focal length and primary points for devices currently running iOS 9.1.</p>
  
  <pre><code>AVCaptureDeviceFormat *format = deviceInput.device.activeFormat;
  CMFormatDescriptionRef fDesc = format.formatDescription;
  CGSize dim = CMVideoFormatDescriptionGetPresentationDimensions(fDesc, true, true);
  
  float cx = float(dim.width) / 2.0;
  float cy = float(dim.height) / 2.0;
  
  float HFOV = format.videoFieldOfView;
  float VFOV = ((HFOV)/cx)*cy;
  
  float fx = abs(float(dim.width) / (2 * tan(HFOV / 180 * float(M_PI) / 2)));
  float fy = abs(float(dim.height) / (2 * tan(VFOV / 180 * float(M_PI) / 2)));
  </code></pre>
  
  <p><strong>NOTE:</strong></p>
  
  <p>I had an initialization issue with this code. I recommend once the values are initialised and correctly set, to save them to a data file and read this file in for the values.</p>