【发布时间】: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