首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVCaptureSession条码扫描

AVCaptureSession条码扫描
EN

Stack Overflow用户
提问于 2013-12-22 22:54:16
回答 2查看 5.5K关注 0票数 7

我目前正在使用AVCaptureSessionAVCaptureMetadataOutput

它工作得很完美,但我只想知道如何仅在AVCaptureVideoPreviewLayer的特定区域上扫描和分析元数据对象。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-23 06:09:20

下面是我的一个项目中的代码示例,它可能会帮助您在正确的轨道上

代码语言:javascript
复制
    // 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];
票数 14
EN

Stack Overflow用户

发布于 2016-06-02 23:34:36

在iOS 9.3.2中,调用metadataoutputRectOfInterestForRect时出现了"CGAffineTransformInvert:奇异矩阵“错误。我能够让它在startRunning方法AVCaptureSession之后调用它

代码语言:javascript
复制
captureSession.startRunning()
let visibleRect = previewLayer.metadataOutputRectOfInterestForRect(previewLayer.bounds)
captureMetadataOutput.rectOfInterest = visibleRect
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20734929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档