gpt4 book ai didi

ios - Swift - captureOutput 帧提取的颜色总是接近黑色

转载 作者:行者123 更新时间:2023-11-28 06:58:57 24 4
gpt4 key购买 nike

我正在尝试处理视频帧并从中提取集中的颜色。我使用的是 AVCaptureStillImageOutput,但每次我拍摄一帧进行处理时它都会发出快门声,所以我切换到 AVCaptureVideoDataOutput 并现在处理每一帧。

这是我使用的代码:

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
currentFrame = self.convertImageFromCMSampleBufferRef(sampleBuffer);
if let image = UIImage(CIImage: currentFrame){
if let color = self.extractColor(image) {
// print the color code
}
}
}

func convertImageFromCMSampleBufferRef(sampleBuffer:CMSampleBuffer) -> CIImage{
let pixelBuffer:CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer);
var ciImage:CIImage = CIImage(CVPixelBuffer: pixelBuffer)
return ciImage;
}

使用 AVCaptureStillImageOutput 我得到的输出几乎是正确的,但是使用 AVCaptureVideoDataOutput 时,即使相机 View 处于强光下,值也总是接近黑色。我猜问题出在帧率或其他问题上,但无法弄清楚。

在最近的几次测试运行中,这是我得到的唯一颜色代码 #1b1f01

我很想使用原始的 AVCaptureStillImageOutput 代码,但它不应该发出快门声音,而且我无法禁用它。

最佳答案

我自己也有同样的问题。只是时间还早。无论出于何种原因,相机传感器从 0 开始,并且愿意在您认为第一帧完全曝光之前为您提供帧。

解决方案:在您期待任何真实图像之前稍等片刻。

关于ios - Swift - captureOutput 帧提取的颜色总是接近黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32537846/

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