Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Adjusting focus for iPhone 6 / 6 Plus #22

Open
edgartronic opened this issue Apr 17, 2015 · 3 comments
Open

Adjusting focus for iPhone 6 / 6 Plus #22

edgartronic opened this issue Apr 17, 2015 · 3 comments

Comments

@edgartronic
Copy link

Hi there.

I've noticed that Card.IO has a tendency to take a photo too quickly on the iPhone 6 & 6 Plus. Not sure if this is due to the camera quality or the SDK detecting edges that don't belong to the card, but it's leading to photos that are unfocused.

I had a look at CardIOGuideLayer.mm, and wondered if upping the float values being used in the 'setVideoFrame:videoFrame' method (line 469) would help make the SDK wait before the user has their card fully focused in the frame. Anywhere else I should considering looking?

Thanks in advance.

@josharian
Copy link
Member

As @dgoldman-ebay has commented elsewhere, card.io was designed to scan, not to take sharp images.

In general, determining absolutely whether an image is in focus is a very hard problem. We do a very crude approximation to this with our focus score calculation, which is probably what you want to look at if, you want to just try fiddling with some thresholds.

Other options include attempting to monitor focus scores over time, waiting for them to stabilize (with hysteresis), in the hopes that that indicates that the camera has finished focusing.

Or perhaps best of all, dig into the camera APIs. I seem to recall that in recent iOS versions, there's a newly-added ability to set the focal depth programatically. It might have to be set per-device, but this could entirely circumvent the entire issue.

Please do experiment with a wide range of lighting conditions and cards. We found that focus scores and related metrics tend to vary greatly...which is why the emphasis was placed on being able to scan blurry cards. :)

@dgoldman-pdx
Copy link
Member

I seem to recall that in recent iOS versions, there's a newly-added ability to set the focal depth programatically.

We're already using the AVCaptureAutoFocusRangeRestrictionNear introduced in iOS 7, which helps somewhat.

iOS 8 added setFocusModeLockedWithLensPosition:completionHandler:. It does indeed look like one could call that to set an initial guess at focus. Doing so also sets the focus mode to AVCaptureFocusModeLocked, so upon completion one would then want to set the focus mode to AVCaptureFocusModeContinuousAutoFocus to resume auto-focusing thereafter.

It will take a bit of experimenting with the lensPosition value. As @josharian speculated, Apple helpfully tells us that A given lens position value does not correspond to an exact physical distance, nor does it represent a consistent focus distance from device to device.

I'm almost talking myself into coding this myself! But I really don't have the time these days.

@dgoldman-pdx
Copy link
Member

See also #21. Maybe you two can work on this together?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants