【问题标题】:Optimise camera for QR codes优化二维码相机
【发布时间】:2015-04-15 09:35:06
【问题描述】:
我有一个AVCaptureDevice 专门用于扫描二维码(使用AVMetadataObjectTypeQRCode)。我的目标是尽可能快地扫描二维码。
AVCaptureDevice 相机的一些设置(例如focus 和exposure)可以在 iOS 中以编程方式进行调整。
我可以对相机进行哪些优化,以最大限度地减少在 iPhone 上捕获 QR 码所需的时间?
【问题讨论】:
标签:
iphone
ios8
camera
qr-code
camera-calibration
【解决方案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];
}