#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(void) {
Mat input_img;
input_img = imread("1 (2).jpg",1);
if (input_img.empty()) { cout << "read image error" << endl;
return -1;
}
namedWindow("原图");
imshow("原图",input_img);
Mat gray_img;
cvtColor(input_img,gray_img,CV_BGR2GRAY);
namedWindow("灰度图");
imshow("灰度图", gray_img);
Mat threshold_img;
threshold(gray_img,threshold_img,0,255,THRESH_BINARY);
namedWindow("threshold_img");
imshow("threshold_img", threshold_img);
vector<vector<Point>> counters;
vector<Vec4i>hier;
findContours(threshold_img, counters, hier, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
drawContours(input_img, counters, -1, Scalar(255, 0, 0), CV_FILLED);
namedWindow("填充图");
imshow("填充图", input_img);
waitKey(0);
return 0;
}
这个是我的程序 只是一个简单的填充轮廓的程序