Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Focus Change Camera or Select Camera #377

Closed
adam1st opened this issue Dec 18, 2023 · 3 comments
Closed

Auto Focus Change Camera or Select Camera #377

adam1st opened this issue Dec 18, 2023 · 3 comments
Labels

Comments

@adam1st
Copy link

adam1st commented Dec 18, 2023

I am making an ingredient scanning app using WeScan and everything is complete however I was testing on an older iPhone with only 1 rear camera. After testing on an iPhone 15 I have realised the rear camera is not auto focusing and I can't see in the library where to define either which camera to use (it needs the closest vision one for scanning small text up close) or how to make it auto focus (eg like in the native camera app you tap to auto focus and it will swap to the appropriate camera).

I have been playing around with the ImageScannerController and CameraScannerViewController to no avail trying to find an autoFocus or selectCamera method, any suggestions? Thanks

@adam1st
Copy link
Author

adam1st commented Dec 19, 2023

I have fixed it, putting this here for others who have the same issue or hoping contributors could possibly add this as a function of the app to chose which lens to use.

  1. I downloaded a local copy of the git
  2. In Xcode I removed the dependency on the package from git (Click on the main blue project icon, package dependencies, WeScan, and clicked - )
  3. Added the package dependancy based on the local copy (so I could alter the files of the package) - XCode, File, Add Package Depdancy, click Add Local button, browse for the local copy and add
  4. The following 4 files were where I found the code is selecting AVCaptureDevice (in Scan and Session folders): CameraScannerViewController, CaptureSessionManager, ScannerViewController, CaptureSession
  5. Search for AVCaptureDevice and replace this: guard let device = AVCaptureDevice.default(for: AVMediaType.video) with the following to CameraScannerViewController and ScannerViewController:

let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: .back)
let selectedDevice = discoverySession.devices.first guard let device = selectedDevice else { return }

  1. Add this to CaptureSession:
    let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: .back)
    let selectedDevice = discoverySession.devices.first self.device = selectedDevice

  2. And add this to CaptureSessionManager:

let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: .back)

let selectedDevice = discoverySession.devices.first guard let device = selectedDevice else { let error = ImageScannerControllerError.inputDevice delegate?.captureSessionManager(self, didFailWithError: error) return nil }

Some links I found helpful:

https://teng.pub/technical/2022/6/9/let-ios-decide-the-best-lens-to-use
https://developer.apple.com/documentation/avfoundation/capture_setup/choosing_a_capture_device

Copy link

This issue is stale because it has been open for 30 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.

@masimplo
Copy link

Is this fix going to be integrated to the codebase at some point? We are facing the same issue and would be nice to not have to fork the repo for this fix.

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

No branches or pull requests

2 participants