Detecting (not decoding!) datamatrix (rectangle) regions in an image

asked 2016-12-15 10:43:20 -0600

logidelic gravatar image

I know that OpenCV doesn't provide any datamatrix decoding. That's ok. I'm currently using zxing to decode datamatrixes and it seems to work well.

However, Sometimes my image may contain two or more datamatrixes. In this case zxing fails because it needs an image with a single datamatrix in it.

Does anyone know how I can detect the datamatrix region? It doesn't have to be perfect as I don't mind false-positives, as long as I also get the rectangle for the actual datamatrix if there is one. I figure that this should be pretty easy with OpenCV since it is essentially trying to find a high-contrast rectangle, but I haven't been able to figure out how to do it...

Any help would be appreciated!

edit retag flag offensive close merge delete

Comments

1

"find a high-contrast rectangle" - MSER, and some estimation, if the outline is square, maybe.

berak gravatar imageberak ( 2016-12-15 10:56:05 -0600 )edit
1

Find two thresholds, mean+xstdDev and mean-xstdDev (pick an appropriate x), then use inRange to set everything between them to zero. Then set everything else to white and look for squares?

Tetragramm gravatar imageTetragramm ( 2016-12-15 20:05:25 -0600 )edit

Thanks for the suggestions! Regarding "finding squares", would you suggest MSER for that?

logidelic gravatar imagelogidelic ( 2016-12-16 15:09:24 -0600 )edit

Well, MSER would be instead of the thresholding thing. But to figure out if something is square, take a look at the sample squares.cpp (or squares.py if you're using python).

Tetragramm gravatar imageTetragramm ( 2016-12-16 15:19:26 -0600 )edit

Appreciate the suggestions here. After some experimentation, I've had good luck with MSER after blurring, resizing and inRanging the image to give me black blobs where the codes are likely to be. It seems to work quite well, except that my results vary dramatically depending on lighting conditions. Any ideas on how I might normalize for these given the steps I mention? I tried the approach mentioned in http://answers.opencv.org/question/75... , but it doesn't seem to solve the issue...

Thanks again.

logidelic gravatar imagelogidelic ( 2016-12-30 13:14:42 -0600 )edit