c.at<float>(rows + 1, j) = 0.0f;
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (inputarray.at<float>(i, j) >= 20.0f) {
p_enlarged_src.at<float>(i + 1, j + 1) = 1.0f;
}
else
p_enlarged_src.at<float>(i + 1, j + 1) = 0.0f;
}
}
/// start to thin
Mat p_thinMat1 = Mat::zeros(rows + 2, cols + 2, CV_32FC1);
Mat p_thinMat2 = Mat::zeros(rows + 2, cols + 2, CV_32FC1);
Mat p_cmp = Mat::zeros(rows + 2, cols + 2, CV_8UC1);
while (bDone != true) {
/// sub-iteration 1
ThinSubiteration1(p_enlarged_src, p_thinMat1);
/// sub-iteration 2
//ThinSubiteration2(p_thinMat1, p_thinMat2);
/// compare
compare(p_enlarged_src, p_thinMat1, p_cmp, CV_CMP_EQ);
/// check
int num_non_zero = countNonZero(p_cmp);
if (num_non_zero == (rows + 2) * (cols + 2)) {
bDone = true;
}
/// copy
p_thinMat1.copyTo(p_enlarged_src);
}
// copy result
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
outputarray.at<float>(i, j) = p_enlarged_src.at<float>(i + 1, j + 1);
}
}
imshow("src", inputarray);
imshow("dst", p_enlarged_src);
waitKey(0);
return 0;
}
附上效果图: