我正在研究在PCB板上检测2D条形码 . 环境是Visual Studio 2012 .
我们遇到了一些问题,无法成功过滤出二维条码图像 .
加载图:原始图像大小为1600 * 1200 .
在我们加载图形并按照以下步骤凝视一系列处理之后:
1. Finding threshold value by auto-threshold method.
2. Doing binary threshold to image.
3. Doing Opening to make image clearly.
打开:dst = open(src,element)= dilate(erode(src,element))
4. Filter out the rectangle except the squares. 然后我们可以得到一组正方形 . 如下图所示,在步骤1-4之后,我们可以在图像上找到正方形 .
5. Using a similar Data Matrix Template compare with squares respectively by the histogram analysis.
5.1计算直方图
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规范化数组的值范围
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比较两个直方图和相关性 .
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我们已经将直方图的区间从256调整到64/32但结果没有鲁棒性,相关值非常低甚至小于0.5 .
6.2我们还尝试使用EMD(地球移动器的距离)来估计两个方格的相似性,但它并没有解决这个问题 .
[[Question]]: 是否可以与我们分享一些改进检测方法的建议?
1 回答
为什么不使用图书馆?
datamatrix opencv module
zxing Cpp
libdmtx
否则,您可以研究这些库中的代码并尝试优化您自己的代码 .