【发布时间】:2014-02-27 22:25:08
【问题描述】:
我需要检测这些线的宽度:
这些线是平行的,上面有一些噪音。
目前,我所做的是:
1.使用细化找中心(张素恩)
ZhanSuenThinning(binImage, thin);
2.计算距离变换
cv::distanceTransform(binImage, distImg, CV_DIST_L2, CV_DIST_MASK_5);
3.围绕中心累加一半距离
double halfWidth = 0.0;
int count = 0;
for(int a = 0; a < thinImg.cols; a++)
for(int b = 0; b < thinImg.rows; b++)
if(thinImg.ptr<uchar>(b, a)[0] > 0)
{
halfWidth += distImg.ptr<float>(b, a)[0];
count ++;
}
4.最后得到实际宽度
width = halfWidth / count * 2;
结果不是很好,大约有 1-2 个像素的误差。在更大的图像上,结果更糟,有什么建议吗?
【问题讨论】:
-
您需要每条线的宽度,还是所有线的宽度始终相同?
-
它们是平行的,宽度相同,只是长度不同
标签: opencv image-processing computer-vision