Detect (and maybe decode) PDF417 barcodes using python

Question:

I am trying to detect the pdf417 barcode (2D barcode) from an image using python.

I will be receiving images of IDs where there is a barcode in them but it might not always be straight. So I am looking for an effective way to DETECT the pdf417 barcode using Python.

I tried all of the available methods that I could find (that uses python)
e.g.,

  • pdf417decoder: requires the image to be cut exactly around the barcode just like in the image below: barcode format required for pdf417decoder

  • pyzbar: only detects 1D barcodes

  • python-zxing and zxing: didn’t detect any of the pdf417 barcodes that I tried (around 10 different IDs – different country)

  • Barcode-detection: this is a DL approach that uses YOLO-V3 to detect barcodes, but again (after trying it), it only detects 1D barcodes…

Is there a method that I missed?
Am I using a wrong approach towards this problem?

  • Possible solution that I am thinking of: using computer vision (some filters and transformations) to detect a box that has black and white dots… Something similar to this.

Thanks!

Asked By: Ammar Mohanna

||

Answers:

After various trials, I ended up using an approach of template matching by OpenCV.
You need to precisely choose your template image that will be the search reference of your algorithm. You need to feed it some grayscaled images.
Then, you need to choose the boxes that have a result higher than a certain threshold (for me 0.55). Then apply NMS (non max suppression) to filter out the noisy boxes.

But keep in mind that there are many edge cases to encounter. If someone is interested to see the complete solution, please let me know.

enter image description here

Answered By: Ammar Mohanna