gpt4 book ai didi

ios - AVCaptureSession条码扫描

转载 作者:可可西里 更新时间:2023-11-01 03:37:12 25 4
gpt4 key购买 nike

我目前正在使用 AVCaptureSessionAVCaptureMetadataOutput

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

最佳答案

这是我的一个项目的代码示例,可以帮助您走上正轨

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

关于ios - AVCaptureSession条码扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20734929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com