Затем мне нужно воссоздать состояние игры в 2D-мини-изображении. -map, и для этого мне нужны края игрового поля бильярдного стола. Я пытался получить их из маски, найденной на предыдущем шаге, но получил совершенно неудовлетворительные результаты. Как можно их улучшить?
Код определения игрового поля:
Код: Выделить всё
Mat src = imread(src_path);
assert(!src.empty());
imshow("Source", src);
Mat hsv;
cvtColor(src, hsv, COLOR_BGR2HSV);
imshow("HSV", hsv);
/* * * * * * * * * * * * * * * * * * * * *
* Start processing BG and PF Masks *
* * * * * * * * * * * * * * * * * * * * */
Mat sharp;
Mat sharpening_kernel = (Mat_(3, 3) src.rows-1) {
// estimating_point should not out of the range in image
continue;
} else {
// uchar delta = (uchar)abs(src.at(center) - src.at(estimating_point));
// delta = (R-R')^2 + (G-G')^2 + (B-B')^2
int delta = int(pow(src.at(center)[0] - src.at(estimating_point)[0], 2)
+ pow(src.at(center)[1] - src.at(estimating_point)[1], 2)
+ pow(src.at(center)[2] - src.at(estimating_point)[2], 2));
if (dest.at(estimating_point) == 0
&& mask.at(estimating_point) == 0
&& delta < thresh) {
mask.at(estimating_point) = 1;
point_stack.push(estimating_point);
}
}
}
}
}



К предыдущим результатам я применяю следующее (обратите внимание, что содержимое argv1 отличается от предыдущего: предыдущий имел начальное изображение, следующий — результат предыдущий фрагмент):
Код: Выделить всё
Mat im = imread(argv[1], 0); // the edge image
Mat kernel = getStructuringElement(MORPH_ELLIPSE, Size(11, 11));
Mat morph;
morphologyEx(im, morph, MORPH_CLOSE, kernel);
int rectIdx = 0;
//vector contours;
//vector hierarchy;
findContours(morph, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE, Point(0, 0));
for (size_t idx = 0; idx < contours.size(); idx++)
{
RotatedRect rect = minAreaRect(contours[idx]);
double areaRatio = abs(contourArea(contours[idx])) / (rect.size.width * rect.size.height);
if (areaRatio > .99)
{
rectIdx = idx;
break;
}
}
//cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78752778/how-can-i-optimize-the-process-to-find-the-best-4-sided-shape-that-contains-my-m[/url]