Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out focal length of camera in ios and what is the sensor height?

Tags:

ios

I had searched every where for finding focal length of the camera and its back sensor height. But I didn't get any specific detail.

I am developing one app which will calculate the actual height of an real world object from the height visible in the image captured from an ios camera.

distance to object (mm) =

focal length (mm) * real height of the object (mm) * image height (pixels) ---------------------------------------------------------------------------
object height (pixels) * sensor height (mm)

here I am having the values distance to object as static, image height in pixel. Now I need focal length and sensor height to find out the real object height.

Thanks in advance. bskania

like image 695
BSKANIA Avatar asked Nov 02 '12 07:11

BSKANIA


2 Answers

EXIF Headers

iOS devices provide the camera's focal-length value in the JPEG EXIF headers. It is visible within iPhoto and just about any other tool.

Options for retrieving it programmatically

  • Apple Technical Q&A QA1622 discusses ALAssetsLibrary
  • Accessing Image Properties uses CGImageSourceRef

The list of EXIF header keys can be found in the CGImageProperties Reference.

NSURL *imageFileURL = [NSURL fileURLWithPath:...];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
if (imageSource == NULL) {
    // Error loading image
    ...
    return;
}

NSDictionary *options = @{kCGImageSourceShouldCache, @NO};
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options);
if (imageProperties) {
    NSNumber *width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
    NSNumber *height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
    NSLog(@"Image dimensions: %@ x %@ px", width, height);
    CFRelease(imageProperties);
}
CFRelease(imageSource);
like image 100
Cameron Lowell Palmer Avatar answered Sep 22 '22 08:09

Cameron Lowell Palmer


The way to solve this issue.

First take one real world object and its measure i.e. height and width.(example of coke cane) Now take a snap of the object that you want to measure. For the iphone or ipad the focal length is fixed to 25mm. Now frame the object that you want to measure on a snap and re-size the real world coke cane image according to the object you want to measure.

use the equation

object_distance = (focal * real_object_height)/object_height;

here, real_object_height = coke cane height; and object_height = coke cane re-sized height

and accordingly measure the height of object using equation

height_of_frame = ((obj_distance) * measured_object_height_in_mm / 1000.0))/focal;

width_of_frame = ((obj_distance) * measured_object_width_in_mm / 1000.0))/focal;

this way you can find out the object distance and its measure. but you need two static data i.e. focal length of camera which you are using and the one real world object measure to compare.

thanks, bskania.

like image 34
BSKANIA Avatar answered Sep 24 '22 08:09

BSKANIA