我使用VNDocumentCameraViewController扫描文档,使用VNRecognizeTextRequest检测文本。只有在纵向模式下扫描文档时,它才起作用。It横向模式它失败了。我可以通过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)
}发布于 2021-01-17 00:59:35
我也有同样的问题。当我启用横向设备定向时,这个问题就解决了。
https://stackoverflow.com/questions/59980388
复制相似问题