stripe-ios icon indicating copy to clipboard operation
stripe-ios copied to clipboard

[FIX] - Enhance card scanner focus with automatic lens selection for improved accuracy and quality

Open akhmedovgg opened this issue 1 year ago • 3 comments

Summary

I've enhanced the camera focus functionality for the card scanner. The camera now automatically selects the optimal lens for the specific range, improving focus and overall scanning accuracy. The system will dynamically switch between lenses as needed, ensuring the best possible image quality for each scan.

Motivation

The card scanner's accuracy and reliability are crucial for user satisfaction and overall system performance. In its previous state, the camera focus was not always optimal, leading to potential issues in scanning quality, especially when handling various card types or environments.

With this update, I've enhanced the camera's focus mechanism by enabling it to automatically select and switch to the most appropriate lens based on the specific scanning destination. This improvement ensures that the camera consistently delivers high-quality, focused images, regardless of the scanning scenario.

By implementing these changes, we can reduce errors in card recognition, speed up the scanning process, and ultimately provide a smoother, more reliable user experience. This update aligns with our commitment to continuous improvement and delivering the best possible solutions to our users.

Testing

This change can only be tested on a physical device, as the card scanner module relies on the AVKit framework.

Before After
stripe stripe2

Changelog

  • [Fixed] - Enhance card scanner focus with automatic lens selection for improved accuracy and quality

akhmedovgg avatar Aug 12 '24 19:08 akhmedovgg

@akhmedovgg I suggest to use this title:

[FIX] - Enhance card scanner focus with automatic lens selection for improved accuracy and quality

mihailsalari avatar Aug 16 '24 20:08 mihailsalari

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 16 '24 21:08 CLAassistant

Just sharing some thoughts, I'm not an IOS dev. So I may be wrong)

  1. Wouldn't AVCaptureDevice.FocusMode.continuousAutoFocus help here? Ref: https://developer.apple.com/documentation/avfoundation/avcapturedevice/focusmode/continuousautofocus/
  2. As I understand the main issue is, that existing implementation doesn't utilize builtInTripleCamera. And it could be solved quick and dirty by just adding another if in the beginning: if let dualCameraDevice = AVCaptureDevice.default( .builtInTripleCamera, for: .video, position: .back ) { defaultVideoDevice = dualCameraDevice } Please correct me if I'm wrong.
  3. Why are there duplicates in preferred and fallback devices? If we don't find device in preferred search, we won't find the same type in fallback search anyway. They are also in different priority order for some reason.
  4. Why do you use different approaches for preferred and fallback searches? What if you utilize DiscoverySession for both?
  5. Why do you even need preferred list, and fallback list, and another fallback to .builtInWideAngleCamera, for: .video, position: .front? What if you just use one prioritized list with DiscoverySession? AVCaptureDevice.DiscoverySession( deviceTypes: [ .builtInTripleCamera, .builtInDualCamera, .builtInDualWideCamera, .builtInWideAngleCamera, .builtInTelephotoCamera, .builtInTrueDepthCamera, .builtInUltraWideCamera], mediaType: .video, position: .unspecified )

return devices.first(where: { device in device.position == .back }) ?? devices.first(where: { device in device.position == .front })

ArtHell avatar Aug 19 '24 13:08 ArtHell

Hi @akhmedovgg! Thanks so much for filing this PR, and I'm very sorry that it took so long to respond!

We've released a fix in iOS SDK 23.30.0: The ultrawide (0.5x) lens will now be used for macro focus in PaymentSheet. We'll issue a similar fix for StripeCardScan in the next minor update.

Your contribution has been credited in the 23.30.0 changelog. Thanks again for identifying and fixing this issue!

davidme-stripe avatar Sep 12 '24 22:09 davidme-stripe

Hi @akhmedovgg! Thanks so much for filing this PR, and I'm very sorry that it took so long to respond!

We've released a fix in iOS SDK 23.30.0: The ultrawide (0.5x) lens will now be used for macro focus in PaymentSheet. We'll issue a similar fix for StripeCardScan in the next minor update.

Your contribution has been credited in the 23.30.0 changelog. Thanks again for identifying and fixing this issue!

Don't forget to say thank you to @mihailsalari, @ArtHell and @MaherBouidani who reviewed this PR and helped for this process.

privacymanifest avatar Sep 12 '24 22:09 privacymanifest