AVCaptureSession条形码扫描 [英] AVCaptureSession barcode scan

查看:129
本文介绍了AVCaptureSession条形码扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 AVCaptureSession AVCaptureMetadataOutput

它完美无缺,但我只是想知道如何指示仅在 AVCaptureVideoPreviewLayer的特定区域扫描和分析元数据对象

It works perfectly, but I just want to know how to indicate to scan and analyze metadata objects only on a specific region of the AVCaptureVideoPreviewLayer?

推荐答案

以下是我所拥有的项目代码示例,可以帮助您走上正轨

Here is a sample of code from a project I have that may help you on the right track

    // 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];

这篇关于AVCaptureSession条形码扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆