【问题标题】:Swift - captureOutput frame extracted color is always coming near to blackSwift - captureOutput 帧提取的颜色总是接近黑色
【发布时间】:2015-09-12 10:39:36
【问题描述】:

我正在尝试处理视频帧并从中提取集中的颜色。我使用的是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,即使相机视图处于强光下,这些值也总是接近黑色。我猜问题出在帧率或其他问题上,但无法弄清楚。

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

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

【问题讨论】:

  • 你找到解决这个问题的方法了吗?

标签: ios swift image-processing ios-camera


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-07-19
    • 2015-11-21
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多