我正在使用VNDocumentCameraViewController
扫描文档和VNRecognizeTextRequest
检测文本。它仅在以纵向模式扫描文档时有效。它的横向模式失败了。我可以传递方向,VNImageRequestHandler
但纵向扫描会失败。同样,如果我尝试检查扫描的图像方向,它总是.up
. 所以我什至无法操纵图像。有人知道如何解决这个方向问题吗?我正在使用下面的代码。
@IBAction func scanTapped(_ sender: UIButton) {
allComponents = [Component]()
let documentCameraViewController = VNDocumentCameraViewController()
documentCameraViewController.delegate = self
self.present(documentCameraViewController, animated: true, completion: nil)
}
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
let image = scan.imageOfPage(at: scan.pageCount-1)
let handler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
do {
try handler.perform([textRecognitionRequest])
} catch {
print(error)
}
controller.dismiss(animated: true)
}