2015-04-15 25 views
2

我有AVCaptureDevice專門掃描QR碼(使用AVMetadataObjectTypeQRCode)。我的目標是儘可能快地掃描QR碼。優化相機QR碼

AVCaptureDevice相機的幾個設置(例如focusexposure)可以在iOS中以編程方式進行調整。

什麼相機的優化,我可以做,以儘量減少需要捕捉到一個iPhone上的QR碼的時間?

回答

1

大多數的這些設置最佳值會根據使用環境(如暗/明亮的房間裏,遠/近QR碼等),所以,除非你知道你的用戶的環境(例如,如果應用程序是專門用於在工廠組裝線),默認值可能是最好的。

但是(根據this source),如果您知道QR碼將靠近相機,您可以通過將autoFocusRangeRestriction設置爲近距離值來加速自動對焦。您還可以確保smoothAutoFocusEnabled設置爲false。

+0

這是完美的,謝謝! – Randomblue

-4

我使用AVCaptureDevice。 這段代碼工作發現我在我的條形碼app.try中使用了這個代碼。

-(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]; 
} 
+0

我在這裏看不到任何手動相機設置。 – Randomblue

+0

好的感謝您的建議... – 1994