mardi 31 mars 2015

Opencv: 2D barcode (Data Matrix) detection

I am working on detect a 2D Barcode on a PCB board. The environment is Visual Studio 2012.


We met some problems and can’t filter out the 2D barcode image successfully.


Loading the figure: Original Image Size is 1600*1200.


After we load the figure and staring a series of processing as following steps:


1. Finding threshold value by auto-threshold method.


2. Doing binary threshold to image.


3. Doing Opening to make image clearly.


Opening: dst = open(src,element) = dilate(erode(src, element))


4. Filter out the rectangle except the squares. Then we can get a collection of squares. As the following image, after the steps 1-4 we can find squares on the image.


5. Using a similar Data Matrix Template compare with squares respectively by the histogram analysis.


5.1 Calculate the histogram


void calcHist( const Mat* images, int nimages, const int* channels, InputArray mask, OutputArray hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false );


5.2 Normalize the value range of an array


void normalize( InputArray src, OutputArray dst, double alpha=1, double beta=0, int norm_type=NORM_L2, int dtype=-1, InputArray mask=noArray());


5.3 Compare two histograms with correlation.


double compareHist( InputArray H1, InputArray H2, CV_COMP_CORREL );


6. After the processing we can’t filter the correct image from the square collection.


6.1 We have adjusted the bins of histogram from 256 to 64/32 but the results without robustness, the correlation values are very low even less than 0.5.


6.2 We also try to use the EMD (Earth Mover's Distance) to estimate the similarity of two squares and it’s not solving this problem.


[[Question]]: Is it possible to share us some suggestion to improve our detection method?


Aucun commentaire:

Enregistrer un commentaire