Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureSession scan QRCode in specific frame

What I need todo is make a Scanner to get the QRCode values.

And I followed the Apple developer documents, use AVCaptureDevice, AVCaptureSession, AVCaptureDeviceInput, AVCaptureVideoPreviewLayer, AVCaptureMetadataOutput to get it works.

_videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

Currently, I get the qrcode successfully, but if there are two or more qrcodes in the camera, we will get several qrcode, so I just want to scan the specific frame on the screen, for example CGRectMake{100, 100, 200, 200}, to make sure there is only one qrcode once we processed.

So, how can we specify the frame we want in the AVCaptureDeviceInput.

Thanks a lot!

like image 371
Wayde Avatar asked Sep 03 '14 12:09

Wayde


1 Answers

Use the rectOfInterest property.

AVCaptureMetadataOutput *metaDataOutput = [[ AVCaptureMetadataOutput alloc] init];
metaDataOutput.rectOfInterest = CGRectMake(0, 0, 0.5f, 0.5f);

 @discussion
    The value of this property is a CGRect that determines the receiver's rectangle of interest for each frame of video.  
    The rectangle's origin is top left and is relative to the coordinate space of the device providing the metadata.  Specifying 
    a rectOfInterest may improve detection performance for certain types of metadata. The default value of this property is the 
    value CGRectMake(0, 0, 1, 1).  Metadata objects whose bounds do not intersect with the rectOfInterest will not be returned.
like image 113
Dávid Kaszás Avatar answered Oct 11 '22 11:10

Dávid Kaszás