gpt4 book ai didi

ios - captureOutput :didOutputSampleBuffer:from connection: 中的方向问题

转载 作者:行者123 更新时间:2023-11-28 06:21:23 27 4
gpt4 key购买 nike

我正在尝试处理 AVCaptureSession 的每一帧并在 UIImageView 中预览过滤后的图像。它有效,但 UIImageView 中的图像出现旋转(和扭曲)。我一直试图在这里和在谷歌中找到答案,但我找不到任何可行的解决方案...有人知道要尝试什么吗?

顺便说一句,我正在使用 Swift 3.0

这是我使用的代码:

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {

let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorMalloc, sampleBuffer!, kCMAttachmentMode_ShouldPropagate)
let coreImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?)
var filteredImage = UIImage(ciImage: coreImage, scale: 1.0, orientation: UIImageOrientation.right)

if filter {
NSLog("FILTER ACTIVATED")
let filterType = CIFilter(name: "CISepiaTone")
filterType?.setValue(coreImage, forKey: kCIInputImageKey)
filterType?.setValue(0.5, forKey: kCIInputIntensityKey)
filteredImage = UIImage(ciImage: filterType!.value(forKey: kCIOutputImageKey) as! CIImage!, scale: filteredImage.scale, orientation: UIImageOrientation.right)
}

DispatchQueue.main.async() {
self.imageViewPreview.image = filteredImage // UIImageView
}
}

这是我在预览中看到的:

UIImageView preview

提前致谢

最佳答案

我找到了!结果我不得不在该方法中添加行 connection.videoOrientation = AVCaptureVideoOrientation.portrait...

关于ios - captureOutput :didOutputSampleBuffer:from connection: 中的方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43333111/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com