AVCaptureSession扫描特定帧中的QRCode

时间:2014-09-03 12:15:01

标签: ios avcapturesession

我需要的是让扫描仪获取QRCode值。

我跟着Apple开发者文档,使用AVCaptureDevice,AVCaptureSession,AVCaptureDeviceInput,AVCaptureVideoPreviewLayer,AVCaptureMetadataOutput来使其工作。

_videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

目前,我成功获得了qrcode,但如果相机中有两个或更多qrcodes,我们将获得几个qrcode,所以我只想扫描屏幕上的特定帧,例如CGRectMake {100,100, 200,200},确保我们处理后只有一个qrcode。

那么,我们如何在AVCaptureDeviceInput中指定我们想要的帧。

非常感谢!

1 个答案:

答案 0 :(得分:5)

使用rectOfInterest属性。

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.