【问题标题】:Optimise camera for QR codes优化二维码相机
【发布时间】:2015-04-15 09:35:06
【问题描述】:

我有一个AVCaptureDevice 专门用于扫描二维码(使用AVMetadataObjectTypeQRCode)。我的目标是尽可能快地扫描二维码。

AVCaptureDevice 相机的一些设置(例如focusexposure)可以在 iOS 中以编程方式进行调整。

我可以对相机进行哪些优化,以最大限度地减少在 iPhone 上捕获 QR 码所需的时间?

【问题讨论】:

    标签: iphone ios8 camera qr-code camera-calibration


    【解决方案1】:

    大多数设置的最佳值因环境而异(例如黑暗/明亮的房间、近/远 QR 码等),因此除非您了解用户的环境(例如,如果该应用专门用于工厂装配线) ,默认可能是最好的。

    但是(根据this source),如果您知道二维码将靠近相机,您可以通过将autoFocusRangeRestriction 设置为近距离值来加快自动对焦。您还可以确保将 smoothAutoFocusEnabled 设置为 false。

    【讨论】:

      【解决方案2】:

      我用的是AVCaptureDevice。 这个代码工作发现我在我的条形码应用程序中使用了这个。试试这个代码。

      -(void)BarcodeStart
      {
      
          _highlightView = [[UIView alloc] init];
      
          _highlightView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;
      
          _highlightView.layer.borderColor = [UIColor lightGrayColor].CGColor;
          _highlightView.layer.borderWidth = 3;
      
          [barcameraView addSubview:_highlightView];
      
          _label = [[UILabel alloc] init];
          _label.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40);
          _label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
          _label.backgroundColor = [UIColor colorWithWhite:0.15 alpha:0.65];
          _label.textColor = [UIColor whiteColor];
          _label.textAlignment = NSTextAlignmentCenter;
          _label.text = @"(none)";
          [self.view addSubview:_label];
          //BackBtn UP side Show
          UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
          //[button addTarget:self action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown];
          UIImageView *img = [[UIImageView alloc] init];
          button.frame = CGRectMake(3,19,30,30);
          img.image = [UIImage imageNamed:@"backBtnImg.png"];
          [button setImage:img.image forState:UIControlStateNormal];
          [_highlightView addSubview:button];
          //
          _session = [[AVCaptureSession alloc] init];
          _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
          NSError *error = nil;
      
          _input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
          if (_input) {
              [_session addInput:_input];
          } else {
              NSLog(@"Error: %@", error);
          }
      
          _output = [[AVCaptureMetadataOutput alloc] init];
          [_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
          [_session addOutput:_output];
      
          _output.metadataObjectTypes = [_output availableMetadataObjectTypes];
      
          _prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
          // _prevLayer.frame = CGRectMake(20, 70, 280, 280);
          _prevLayer.frame = barcameraView.bounds;
          _prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
          [barcameraView.layer addSublayer:_prevLayer];
      
          [_session startRunning];
      
          [barcameraView bringSubviewToFront:_highlightView];
          [self.view bringSubviewToFront:_label];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-10
        • 1970-01-01
        • 2015-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-07
        相关资源
        最近更新 更多