VNDocumentCameraViewController 和 AVCaptureStillImageOutput 的图像差异?

Image difference from VNDocumentCameraViewController and AVCaptureStillImageOutput?

请朋友们告诉我VNDocumentCameraViewController和AVCaptureStillImageOutput获取的图片有什么区别

我用它来使用VNRecognizeTextRequest进行文本识别,当我从VNDocumentCameraViewController获取图像时,文本被完美识别,而当我只是从AVCaptureStillImageOutput中拍摄照片时,文本不想被识别。非常感谢。

我遇到了同样的问题,在我的例子中,将方向传递给 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
    }
}

此外,AVCaptureStillImageOutput 已弃用,您应该尽可能使用 AVCapturePhotoOutput。