4

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.

Chuck Krutsinger
  • 2,830
  • 4
  • 28
  • 50
  • 1
    Where is a valid sample of the MD dl/id? – Brad Brighton Mar 16 '15 at 00:19
  • @BradBrighton I have the barcode from someone's actual license. I cannot share that for obvious reasons. I guess I'm just asking if anyone else has seen this problem and if and how they were able to overcome it. My product is able to recognize the barcodes on a number of different state licenses, but the api mentioned in the OP is simply not recognizing the barcode on the Maryland licenses that I have tried. – Chuck Krutsinger Mar 16 '15 at 03:43
  • Of course you can't share a real license. However, if there is a formal sample, you can determine if it's the license or the state standard that's giving you issues. I also have code for multiple states, but MD isn't one I've gotten to yet, and the relevant standards are pretty clear about compatibility. – Brad Brighton Mar 16 '15 at 03:46
  • @BradBrighton - I have not found anything on line that provides a reference standard for Maryland. If you know of a source, please share. I have found reference samples from about 20 different states, but not MD. – Chuck Krutsinger Mar 16 '15 at 14:32
  • No, not specific to Maryland, but to the DL/id card specs themselves. – Brad Brighton Mar 16 '15 at 14:35
  • @BradBrighton - Yes, I have the specs. I have been parsing license content for a couple of years now. I can even parse Maryland's content when read using a laser scanner attachment. The problem is that the iOS library mentioned above does not seem to read the barcode. My laser scanners have no problem reading the barcode. That is why I am posting this question to see if anyone else has run into this issue and if and how they might have resolved it. – Chuck Krutsinger Mar 16 '15 at 16:36
  • 2
    I have logged a bug with Apple. – Chuck Krutsinger Mar 19 '15 at 19:54
  • One thing you haven't mentioned (and I hadn't asked, to this point) is which device(s) you're trying to do this with. Since there were some significant variations of camera and focus quality over time, is that playing a role? I've definitely had variability of scan success across devices due to this. – Brad Brighton Mar 24 '15 at 23:27
  • Thanks for posting this! Very much helped our investigation as well. – Bob Spryn Nov 04 '16 at 20:35
  • @BobSpryn We continue to have great difficulty using the camera to scan Maryland license barcodes, whereas other stats scan quite easily. Not able to discern the reason. Please share if you discover anything. – Chuck Krutsinger Nov 04 '16 at 21:01

1 Answers1

3

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.

zimmryan
  • 1,099
  • 10
  • 19
  • According to the results from the Honeywell and Infinite Peripherals attachments, it is a PDF417 barcode and those devices are able to scan it. As I told the @Brad, I have been doing this for some time and successfully scan barcodes in my products that have been shipping since shortly after iOS 7 was released. My code also works. However, I never get a call back from the AVFoundation framework on this particular barcode from Maryland. It's not my code, it's the framework that failed to recognize it for some reason. – Chuck Krutsinger Mar 21 '15 at 02:59
  • All US and Canadian driver's licenses use PDF417 barcodes. See http://www.aamva.org/Driver-Licensing-Identification/ The barcode is most definitely a PDF417, but perhaps has some variation of the spec that Apple's library is not able to interpret. The specification for PDF417 is very complex and includes choices of error correction and other parameters that may be causing problems in this case. – Chuck Krutsinger Mar 23 '15 at 02:09
  • 1
    @ChuckKrutsinger The only other thing is that the barcode may be to large for the camera, if it has to many characters the iPhones camera may not have the resolution needed to identify the pixels. I was able to replicate the problem listed here, where I could not scan the first PDF417 until it was up-rezzed then it scanned fine. https://github.com/PDF417/pdf417-android/issues/1 – zimmryan Mar 23 '15 at 14:18
  • That could be the problem,but I don't think so. The scan fails on the actual license. – Chuck Krutsinger Mar 23 '15 at 18:38
  • @ChuckKrutsinger please see the edits, I have a working MD license now. – zimmryan Mar 24 '15 at 21:34
  • are you saying you couldn't scan the actual license, only an enhanced photo shop image of it? Did you have access to the actual license? – Chuck Krutsinger Mar 24 '15 at 21:49
  • @ChuckKrutsinger I started with an image of the back of a MD license (720p resolution full size), not a physical copy. It was not scannable. Taking that 720p image and enhancing it in PS I was able to get it to scan. So the end result was that the PDF417 barcode on a MD license is readable by the AVFramework. – zimmryan Mar 25 '15 at 00:38
  • I am unable to get it to work with actual licenses, which is the requirement I'm trying to meet. – Chuck Krutsinger Mar 25 '15 at 03:50
  • 1
    Ok. Much ado about nothing. Turns out that the density of the Maryland license barcode has made scanning with the camera very tricky. With a steady hand, just the right amount of light, and some patience, it does work. – Chuck Krutsinger Mar 26 '15 at 18:13
  • @ChuckKrutsinger interesting, glad it all worked out. – zimmryan Mar 26 '15 at 18:22
  • Thanks for sticking with me as I bumbled through this. – Chuck Krutsinger Mar 26 '15 at 19:02