【发布时间】:2016-06-16 19:30:11
【问题描述】:
有什么方法可以使用 OpenCV 将光环的中心孔设置为白色像素,这样我就可以得到一个纯白色的圆圈?我尝试过使用扩张和侵蚀形态函数。它们使图像更清晰(如您所见),但中心仍然是黑色。
【问题讨论】:
有什么方法可以使用 OpenCV 将光环的中心孔设置为白色像素,这样我就可以得到一个纯白色的圆圈?我尝试过使用扩张和侵蚀形态函数。它们使图像更清晰(如您所见),但中心仍然是黑色。
【问题讨论】:
你可以简单的找到外轮廓,然后填充整个轮廓:
代码:
#include <opencv2\opencv.hpp>
#include <vector>
using namespace std;
using namespace cv;
int main()
{
// Read grayscale image
Mat1b img = imread("path_to_image", IMREAD_GRAYSCALE);
// Find external contour
vector<vector<Point>> contours;
findContours(img.clone(), contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// Check that you find something
if (!contours.empty())
{
// Fill the first (and only) contour with white
drawContours(img, contours, 0, Scalar(255), CV_FILLED);
}
// Show result
imshow("Filled", img);
waitKey();
return 0;
}
【讨论】: