Stephen Hsu
Stephen Hsu

Reputation: 5187

How to capture images continuously with AV Foundation?

I'm trying to implement QRcode reader with AV Foundation. My plan is capturing images continuously, sending captured images to QRcode detector until a valid code is recognized. The detector needs CGImageRef or UIImage as input. My questiones are:

  1. Which output should I use: AVCaptureVideoDataOutput or AVCaptureStillImageOutput?
  2. How to take images continuously each, for example, 500ms? How long the interval should be?

Upvotes: 0

Views: 981

Answers (2)

tejusadiga2004
tejusadiga2004

Reputation: 311

Create an instance of AVCaptureVideoDataOutput. Set the sampleBufferDelegate of AVCaptureDataOutput to whatever class (say x)you want to receive the sample buffer. Confirm class x to AVCaptureVideoDataOutputSampleBufferDelegate protocol. Implement– captureOutput:didOutputSampleBuffer:fromConnection: method of that protocol in class x. Add AVCaptureVideoDataOutput instance to AVCaptureSession. Then start the session. You will receive the callback with sample buffer.

Upvotes: 0

tejusadiga2004
tejusadiga2004

Reputation: 311

AVCaptureVideoDataOutput gives you the Uncompressed YUV frame which you can easily send to QRCode reader if it supports uncompressed inputs. Hence you will be avoiding decoding operation.

If AVCaptureVideoDataOutput is used you can set frame rate in AVFormatDescription and set that to AVCaptureDevice. Once you start the AVCaptureSession you receive frames continuously at the specified frame rate until you stop it. Typically you can set 5 fps and make sure that this operation is asynchronous and you preferably process QRCode in a different thread so that in between two frame capture events you process the QRCode decode operation.

Upvotes: 1

Related Questions