opencv c++ 填充轮廓曲线
时间: 2024-01-01 09:04:28 浏览: 49
以下是使用OpenCV C++填充轮廓曲线的示例代码:
```cpp
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
// 读取图像
Mat image = imread("image.jpg");
// 转换为灰度图像
Mat gray;
cvtColor(image, gray, COLOR_BGR2GRAY);
// 二值化处理
Mat binary;
threshold(gray, binary, 0, 255, THRESH_BINARY);
// 查找轮廓
std::vector<std::vector<Point>> contours;
findContours(binary, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// 填充轮廓曲线
for (int i = 0; i < contours.size(); i++)
{
drawContours(image, contours, i, Scalar(0, 0, 255), FILLED);
}
// 显示结果
imshow("Filled Contours", image);
waitKey(0);
return 0;
}
```
这段代码首先读取一张图像,然后将其转换为灰度图像,并进行二值化处理。接下来,使用`findContours`函数查找图像中的轮廓。最后,使用`drawContours`函数填充轮廓曲线,并将结果显示出来。