由于某些原因,从CaptureOutput获取CIImage之后,像这样:
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
let ciImage = CIImage(cvPixelBuffer: imageBuffer)
self.inputImage = ciImage
let handler = VNImageRequestHandler(ciImage: ciImage, orientation: .right)
DispatchQueue.global(qos: .userInteractive).async {
do {
try handler.perform([self.rectanglesRequest])
} catch {
print(error)
}
然后,在另一个函数中将其转换为UIIImage:
imageView.image = UIImage(ciImage: self.inputImage, scale: 1, orientation: .right)
我仍然看到图像在imageView中向左旋转。我究竟做错了什么?谢谢!
答案 0 :(得分:0)
我个人确实记得遇到过这样的问题,最终改变了图像的方向。不确定为什么会这样。
但是请尝试一下,如果可能的话请调整代码以匹配您的代码。
func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
guard error == nil else { return }
if let sampleBuffer = photoSampleBuffer, let previewBuffer = previewPhotoSampleBuffer, let dataImage = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewBuffer) {
guard let capturedImage = UIImage(data: dataImage) else { return }
setThumbnail(image: capturedImage) // Set image as a thumbnail
addCaptured(image: capturedImage) // Add capture image into image collection
} else {
// print("Error: Failed to present data image.")
}
}