Reputation: 3125
I am using Google ML Kit and iPad Air 4 for bar code scanning. For PDF417 bar code back camera works fine. I am not able scan PDF417 using front camera. Is there any settings/code I need to do for front camera?
- (void)captureOutput:(AVCaptureOutput *)output
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
if (imageBuffer) {
// Evaluate `self.currentDetector` once to ensure consistency throughout this method since it
// can be concurrently modified from the main thread.
Detector activeDetector = self.currentDetector;
//[self resetManagedLifecycleDetectorsForActiveDetector:activeDetector];
_lastFrame = sampleBuffer;
MLKVisionImage *visionImage = [[MLKVisionImage alloc] initWithBuffer:sampleBuffer];
UIImageOrientation orientation = [UIUtilities
imageOrientationFromDevicePosition:_isUsingFrontCamera ? AVCaptureDevicePositionFront
: AVCaptureDevicePositionBack];
visionImage.orientation = orientation;
CGFloat imageWidth = CVPixelBufferGetWidth(imageBuffer);
CGFloat imageHeight = CVPixelBufferGetHeight(imageBuffer);
BOOL shouldEnableClassification = NO;
BOOL shouldEnableMultipleObjects = NO;
switch (activeDetector) {
case DetectorOnDeviceBarcode: {
MLKBarcodeScannerOptions *options = [[MLKBarcodeScannerOptions alloc] init];
[self scanBarcodesOnDeviceInImage:visionImage
width:imageWidth
height:imageHeight
options:options];
break;
}
}
} else {
if (kTrace) NSLog(@"%@", @"Failed to get image buffer from sample buffer.");
}
}
Upvotes: 0
Views: 620