朋友们,请告诉我从VNDocumentCameraViewController和AVCaptureStillImageOutput获取的图片有什么不同。
我使用VNRecognizeTextRequest将其用于文本识别,当我从VNDocumentCameraViewController获得图像时,文本可以完美地识别,而当我只是从AVCaptureStillImageOutput拍摄照片时,文本不想被识别。非常感谢。
发布于 2021-05-25 23:07:44
我也有同样的问题,在我的例子中,将方向传递给VNImageRequestHandler解决了这个问题。
您可以使用imageOrientation属性从UIImage获取UIImage.Orientation。
VNImageRequestHandler需要一个CGImagePropertyOrientation,因此您必须使用以下内容对其进行转换:
func convert(orientation: UIImage.Orientation) -> CGImagePropertyOrientation {
switch orientation {
case .up: return .up
case .upMirrored: return .upMirrored
case .down: return .down
case .downMirrored: return .downMirrored
case .left: return .left
case .leftMirrored: return .leftMirrored
case .right: return .right
case .rightMirrored: return .rightMirrored
@unknown default: return .up
}
}此外,如果可以,您应该使用AVCapturePhotoOutput,因为AVCaptureStillImageOutput已弃用。
https://stackoverflow.com/questions/67054102
复制相似问题