Mat thinning_select=imread("image.png",0);
ximgproc::thinning(select, thinning_select, ximgproc::THINNING_ZHANGSUEN);
vector<Vec4i> lines;
HoughLinesP(thinning_select, lines, 1, CV_PI / 180, 80, 30,3);
Mat show_line = thinning_select.clone() = 0;
for (size_t i = 0; i < lines.size(); i++)
{
line(show_line, Point(lines[i][0], lines[i][1]),
Point(lines[i][2], lines[i][3]), Scalar(255), 3);
}
Mat select_float;
distanceTransform(select, select_float, DIST_C, 3);
double t_min, t_max;
Point min_point, max_point;
minMaxLoc(select_float, &t_min, &t_max, &min_point, &max_point, show_line);
cout << t_max << endl;
I will get the result 4
as the above code
Try the distance transform on the image and the mean value along the line will give the width.
Actually I have done the distance transform, but I don't know how to pick the width from those distance
you can use thinning function to get sketon line.
If you've got problem with square you can mixed distance transform and thinning results using a mask to filter line width
@LBerger Hard to implement your solution.. See the flowing answer, If you have better thinking, tell me pleasing