我有一组平假名字符,并希望计算字符具有的端点/尖端数量。
例如: 输入图像: 期望输出图像: 我尝试使用凸包 代码:(基于OpenCV教程here)
例如: 输入图像: 期望输出图像: 我尝试使用凸包 代码:(基于OpenCV教程here)
findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
vector<vector<Point> >hull(contours.size());
for (int i = 0; i < contours.size(); i++)
{
convexHull(Mat(contours[i]), hull[i], false);
}
Mat drawing = Mat::zeros(threshold_output.size(), CV_8UC3);
for (int i = 0; i< contours.size(); i++)
{
if (hierarchy[i][3] == 0) {
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point());
}
}
然后使用conrnerHarris()函数,但它返回了太多不需要的角点。
代码:(基于opencv教程这里)
int blockSize = 2;
int apertureSize = 3;
/// Detecting corners
drawing = binarizeImage(drawing); // otsu's
cornerHarris(drawing, dst, blockSize, apertureSize, 0.04, BORDER_DEFAULT);
/// Normalizing
normalize(dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
convertScaleAbs(dst_norm, dst_norm_scaled);
int countCorner = 0;
/// Drawing a circle around corners
for (int j = 0; j < dst_norm.rows; j++)
{
for (int i = 0; i < dst_norm.cols; i++)
{
if ((int)dst_norm.at<float>(j, i) > 50)
{
circle(output, Point(i, j), 2, Scalar::all(255), -1, 8, 0);
countCorner++;
}
}
}
它检测到了11个角落。
我认为这可能与指尖检测相同,但我不知道如何实现。
[我正在使用OpenCV 2.4.9。]