Mat srcMat4(srcMat3.size(), CV_8UC1);
srcMat3.convertTo(srcMat4, CV_8UC1, 255, 0);
vector<vector<Point>>contours;
vector<Vec4i>hierarchy;
findContours(srcMat4, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
vector<Moments> mu(contours.size());
int index = -1;
int max = 0;
for (int i = 0; i < contours.size(); i++)
{
mu[i] = moments(contours[i], true);
Mat hu;
HuMoments(mu[i], hu); //计算Hu矩
double area = contourArea(contours[i]);
if (area > max) {
max = area;
index = i;
}
}
Mat srcMat5 = Mat::zeros(srcMat4.size(), CV_8UC1);
drawContours(srcMat5, contours, index, Scalar(255), FILLED);
Mat srcMat6(srcMat5.size(), CV_8UC1);
ximgproc::thinning(srcMat5, srcMat6, ximgproc::THINNING_ZHANGSUEN);
?
?
?
?
?
?
|