注:非矩形ROI的提取都需要进行mask操作。
圆形ROI:
void main()
{
//1、建立圆形腌膜,2、将需要处理的地方复制出来,3、对整个图片进行处理后,贴到原始图像
Mat srcImg, resImg, roi;
srcImg = imread("lenna.jpg");
resImg = Mat(srcImg.size(),srcImg.type()); //作为要处理的图片
roi = Mat::zeros(srcImg.size(), CV_8UC1);
circle(roi, Point(130, 100), 50, CV_RGB(255, 255, 255), -1);//mask建立
cv::subtract(srcImg, srcImg, resImg, roi);
srcImg.copyTo(resImg, roi);
GaussianBlur(resImg, resImg, Size(5, 5), 0);//高斯滤波
resImg.copyTo(srcImg, roi);
}
不规则ROI,只有一些轮廓点:
Mat img = imread(IMG_PATH);
Mat dst;
Mat roi = Mat::zeros(img.size(),CV_8U);
vector<vector<Point>> contour;
vector<Point> pts;
pts.push_back(Point(30,45));
pts.push_back(Point(100,15));
pts.push_back(Point(300,145));
pts.push_back(Point(330,240));
pts.push_back(Point(50,250));
contour.push_back(pts);
drawContours(roi,contour,0,Scalar::all(255),-1);
img.copyTo(dst,roi);