我正在使用AVFoundation识别文本并执行OCR.如何添加自动对焦?当用户点击屏幕时,我不希望有黄色方块的东西,我只是想让它自动关注对象,例如信用卡.
这是我的会话代码.
func setupSession() { session = AVCaptureSession() session.sessionPreset = AVCaptureSessionPresetHigh let camera = AVCaptureDevice .defaultDeviceWithMediaType(AVMediaTypeVideo) do { input = try AVCaptureDeviceInput(device: camera) } catch { return } output = AVCaptureStillImageOutput() output.outputSettings = [ AVVideoCodecKey: AVVideoCodecJPEG ] guard session.canAddInput(input) && session.canAddOutput(output) else { return } session.addInput(input) session.addOutput(output) previewLayer = AVCaptureVideoPreviewLayer(session: session) previewLayer!.videoGravity = AVLayerVideoGravityResizeAspect previewLayer!.connection?.videoOrientation = .Portrait view.layer.addSublayer(previewLayer!) session.startRunning() }