我目前正在使用AVCaptureSession和AVCaptureMetadataOutput。
它工作得很完美,但我只想知道如何仅在AVCaptureVideoPreviewLayer的特定区域上扫描和分析元数据对象。
发布于 2013-12-23 06:09:20
下面是我的一个项目中的代码示例,它可能会帮助您在正确的轨道上
// where 'self.session' is previously setup AVCaptureSession
// setup metadata capture
AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
[self.session addOutput:metadataOutput];
[metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[metadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeEAN13Code]];
// setup preview layer
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
previewLayer.frame = self.previewView.bounds;
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
// we only want the visible area of the previewLayer to accept
// barcode input (ignore the rest)
// we need to convert rects coordinate system
CGRect visibleMetadataOutputRect = [previewLayer metadataOutputRectOfInterestForRect:previewLayer.bounds];
metadataOutput.rectOfInterest = visibleMetadataOutputRect;
// add the previewLayer as a sublayer of the displaying UIView
[self.previewView.layer addSublayer:previewLayer];发布于 2016-06-02 23:34:36
在iOS 9.3.2中,调用metadataoutputRectOfInterestForRect时出现了"CGAffineTransformInvert:奇异矩阵“错误。我能够让它在startRunning方法AVCaptureSession之后调用它
captureSession.startRunning()
let visibleRect = previewLayer.metadataOutputRectOfInterestForRect(previewLayer.bounds)
captureMetadataOutput.rectOfInterest = visibleRecthttps://stackoverflow.com/questions/20734929
复制相似问题