2

I am trying to process the video frames and extracting the concentrated color out of it. I was using the AVCaptureStillImageOutput but it was making the shutter sound everytime I take a frame for the processing so I switched to AVCaptureVideoDataOutput and now processing each frame as it comes by.

Here is the code I am using:

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;
    }

With the AVCaptureStillImageOutput I was getting almost correct output but with the AVCaptureVideoDataOutput the values are always near to black even if the camera view is into the bright light. I am guessing the problem is around the framerate or something but not able to figure it out.

In the last few test run this is the only color code I am getting #1b1f01

I would love to use the original AVCaptureStillImageOutput code but it should not make the Shutter sound and I am not able to disable it.

dhaval
  • 7,611
  • 3
  • 29
  • 38

1 Answers1

2

Had this same issue myself. It was just that it was very early; for whatever reason the camera sensor starts at 0 and is willing to give you frames before what you'd think of as the first frame is fully exposed.

Solution: just wait a second before you expect any real images.

Jim Driscoll
  • 894
  • 11
  • 8