2014-09-03 92 views
4

我需要的是讓掃描儀獲取QRCode值。AVCaptureSession掃描特定幀中的QRCode

而且我遵循Apple開發者文檔,使用AVCaptureDevice,AVCaptureSession,AVCaptureDeviceInput,AVCaptureVideoPreviewLayer,AVCaptureMetadataOutput來獲得它的工作。

_videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

目前,我得到的QR碼成功,但如果有相機兩個或兩個以上qrcodes,我們會得到一些QRCode的,所以我只想掃描屏幕上的特定幀,例如CGRectMake { 100,100,200,200},以確保我們處理後只有一個qrcode。

那麼,我們如何在AVCaptureDeviceInput中指定我們想要的幀。

非常感謝!

回答

4

使用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. 
+0

謝謝,它的工作原理。 – 2014-09-05 01:27:44