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.
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.
Any help will be appreciated.
EDIT:
Deduced values are as follows (using iPhone 6, camera feed resolution 1280x720):
fx=1229
cx=360
fy=1153
cy=640
This code provides an accurate estimate for the focal length and primary points for devices currently running iOS 9.1.
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)));
NOTE:
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.
In my non-OpenCV AR application I am using field of view (FOV) of the iPhone's camera to construct the camera projection matrix. It works alright for displaying the Sun path overlaid on top of the camera view. I don't know how much accuracy you need. It could be that knowing only FOV would not be enough you.
iOS API provides a way to get field of view of the camera. I get it as so:
After getting the FOV I compute the projection matrix:
where