ビデオフレームを処理して、そこから集中した色を抽出しようとしています。を使用して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
ですが、シャッター音を鳴らすべきではなく、無効にすることもできません。