Chuck Krutsinger
Chuck Krutsinger

Reputation: 2930

AVMetadataObjectTypePDF417Code not able to read Maryland drivers license

I have been shipping an app for some time that uses AVFoundation Framwork to read the PDF417 barcode on a driver's license in order to capture data. Works great with a number of different state drivers' licenses. However, I have been unable to get it to read any license from the state of Maryland. My app also can use optional attachments from Honeywell or Infinite Peripherals that read barcodes using a laser scanner. Those attachments are able to read the same Maryland barcodes easily.

What should happen is a callback to:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection

But the callback never occurs when scanning the barcode on a Maryland license. It does for any other state license that I have so far tried. I have not yet had this problem with any other state issued licenses, but I have not tried them all yet.

Has anyone else seen this issue?

Update: This is not a question about how to use the AVFoundation framework to read a barcode. I have multiple products in the app store that do just that, including PDF417 codes. And the barcode in question is most definitely a PDF417 barcode because the USA requires all 50 states and Puerto Rico to put a PDF417 barcode on their licenses.

Final Status: I was able to scan MD licenses. Turns out they contain quite a bit more data than other license formats I had been working with. As a result, scanning them using a camera requires better lighting and a steadier hand than other less dense barcodes. It can be done and does work. I have decided to leave this question up so that anyone else who has this problem can see the solution posted below and can understand that it is possible.

Upvotes: 4

Views: 2010

Answers (1)

zimmryan
zimmryan

Reputation: 1099

I can successfully scan PDF417 codes using the code below.

Edit: After tracking down a sample MD license I can indeed scan it successfully using AVCapture, but only after editing the image in Photoshop.

-(void)setupBarcode
{
    AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error = nil;

    _input = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
    [self.captureSession addInput:_input];

    _output = [[AVCaptureMetadataOutput alloc] init];
    [_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
    [self.captureSession addOutput:_output];

    _output.metadataObjectTypes = [_output availableMetadataObjectTypes];
    self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
}

-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
    AVMetadataMachineReadableCodeObject *barCodeObject;
    NSString *detectionString = nil;
    for (AVMetadataObject *metadata in metadataObjects) 
    {
        if ([metadata.type isEqualToString:AVMetadataObjectTypePDF417Code])
        {
            barCodeObject = (AVMetadataMachineReadableCodeObject *)[self.previewLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata];
            detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
           break;
        }
        else
        {
            //What do you get for this line if it doesn't decode?
            NSLog(@"%@",metadata.type);
        }
    }
    NSLog(@"%@",detectionString);
}

In order to get the MD license to scan properly I had to import an image of the license into Photoshop, adjust the contrast, resolution and antialiasing, and then it scanned perfectly and returned me the correct string with all the appropriate drivers license fields.

I believe this is due to the resolution of the camera combined with the resolution of the printed DL. Certain fields (like the left row indicator) are not being read clearly.

Upvotes: 3

Related Questions