//多边形的点已经给出,两点间连直线得到ROI
#include <opencv2/core/core.hpp>
#include<opencv2/opencv.hpp>
#include<iostream>
#include <string>
using namespace cv;
using namespace std;
int main() {
Mat image = imread("../data/lena-gray.jpg");
if(image.empty()) {
cout << "image is empty" << endl;
return 0;
}
imshow("SRC", image);
Mat mask = Mat::zeros(image.size(), CV_8UC1);
Point p1 = { 25, 60 };
Point p2 = { 50, 110 };
Point p4 = { 100, 60 };
Point p3 = { 100, 110 };
Point p5 = { 50, 10 };
vector<Point> contour;
contour.push_back(p1);
contour.push_back(p2);
contour.push_back(p3);
contour.push_back(p4);
contour.push_back(p5);
vector<vector<Point> > contours;
contours.push_back(contour);
cv::drawContours(mask, contours, -1, cv::Scalar::all(255), FILLED);
imshow("maskRegion", mask);
Mat maskImage;
image.copyTo(maskImage, mask);
imshow("getMaskImage", maskImage);
waitKey(0);
return 0;
}
opencv-给出点,利用drawContours得到ROI
最新推荐文章于 2022-01-26 13:53:59 发布