Контраст и черно-белое устройство ввода AVCaptureSession
Я пытаюсь реализовать сканер штрих-кода, используя собственное программное обеспечение Apple... Я обнаружил, что сканирование очень хорошо работает на черном на белом... однако в реальной ситуации мы находим, что контраст немного ниже (см. Изображение)
Теперь мне интересно, если у кого-нибудь есть идея, как установить контраст на AVCaptureSession/AVCaptureDevice для сканирования штрих-кода... Все, что я нашел до сих пор, касается эффекта наложения для изменения цвета, однако я не уверен, что это будет результат в желаемых эффектах, так как устройство все еще видит цвет, и пользователь видит черный и белый...
Мой код установки сканера выглядит следующим образом:
-(void)setupBarcodeScanner
{
// Create a new AVCaptureSession
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
// Want the normal device
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if(input) {
// Add the input to the session
[session addInput:input];
} else {
NSLog(@"error: %@", error);
return;
}
if ([device lockForConfiguration:&error]) {
[device setExposureModeCustomWithDuration:CMTimeMake(1,10) ISO:AVCaptureISOCurrent completionHandler:nil];//setExposureModeCustomWithDuration:200 ISO:AVCaptureISOCurrent completionHandler:nil];
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
[device setSmoothAutoFocusEnabled:YES];
[device setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
[device setFlashMode:AVCaptureFlashModeOn]; //might be removed
[device unlockForConfiguration];
}
AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
// Have to add the output before setting metadata types
[session addOutput:output];
// What different things can we register to recognise?
NSLog(@"%@", [output availableMetadataObjectTypes]);
// We're only interested in QR Codes
[output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode,AVMetadataObjectTypeDataMatrixCode]];
// This VC is the delegate. Please call us on the main queue
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
// Display on screen
_previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
_previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
_previewLayer.bounds = CGRectMake(0, 0, self.view.frame.size.width, 160);
_previewLayer.position = CGPointMake(CGRectGetMidX(_previewLayer.bounds), CGRectGetMidY(_previewLayer.bounds));
[self.view.layer addSublayer:_previewLayer];
// Add the view to draw the bounding box for the UIView
_boundingBox = [[SCShapeView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 160)];
_boundingBox.backgroundColor = [UIColor clearColor];
_boundingBox.hidden = YES;
[self.view addSubview:_boundingBox];
// Start the AVSession running
[session startRunning];
}
Мы пытаемся отсканировать штрих-код матрицы данных... Любая помощь по этому вопросу будет принята с благодарностью.