Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to use OpenCV to detect 2D barcodes in a static image but the documentation doesn't seem to cover it

OpenCV has some tutorials that deal with trying to detect patterns in a live video stream. E.g.:

http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html

However, that is not really what I'm trying to do. I have static images, such as .jpgs, that include 2D barcodes.

My goal is to isolate one or more 2D barcodes from the image. If the .jpg is 1000 pixels by 500 pixels, and the 2D barcode is just 200 pixels by 200 pixels, I just want to save the 200x200 pixel sample to an output file.

I suspect that this requires either a Haar cascade or an LBP cascade. I suspect feature detection won't be able to do this.

However, I can't find any tutorials that address this problem.

Further, the opencv distribution automatically builds some executables that seem to be related, such as opencv_perf_objdetect and opencv_test_objdetect, but they don't seem to correspond to the tutorials, nor to anything else in the documentation.

Question: Is the problem of how to detect sub-images within a static image actually explained somewhere in the OpenCV documentation? If so, where?

Thanks.

like image 414
dataquerent Avatar asked Apr 08 '14 07:04

dataquerent


People also ask

Can OpenCV read barcode?

It can be used to detect areas that may contain a barcode and eliminate most background. Then the precise barcode area can be found according to other barcode features.


1 Answers

I was recently working on a barcode detection project. At the beginning I supposed that a simple machine learning algorithm combined with a texture-based descriptor can resolve the barcode detection. However, I have experienced several problems because in the case of my application I don’t know if there is a barcode or not, it’s size, it’s type (UPC-A, EAN …), it’s orientation… which supposes to try many combinations in order to localize the barcode.

I also didn’t dispose of or have the time to create a training dataset adequate to the type of images I have, so I didn’t continue with this solution. Then I have read several articles. Many dedicated barcode detection methods start from the assumption that there is a barcode in the image and so they are trying to find it. Moreover, some of the algorithms suppose that the barcode is horizontal, and use this hypothesis as an a priori information.

The best solution I have found is BLaDE (http://www.ski.org/Rehab/Coughlan_lab/BLaDE/BLaDE_TechReport.pdf). The code is also available on the web, so you can easily test it. The only problem is that it was designed only for UPC-A barcodes.

To resume, the best solution for you depends on several aspects:

  • the type of barcode

  • you know for sure that there is a barcode

  • it’s orientation: any/a given angle

  • real time application/device to run it

  • you dispose of a training set

Good luck!

like image 188
Raluca Avatar answered Oct 01 '22 17:10

Raluca