简体   繁体   中英

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

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

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

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);

The way to solve this issue.

First take one real world object and its measure ie 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 ie focal length of camera which you are using and the one real world object measure to compare.

thanks, bskania.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM