1 #include <opencv2/opencv.hpp> 2 #include <iostream> 3 4 using namespace cv; 5 using namespace std; 6 7 int main(int argc, char** argv) 8 { 9 Mat src = imread("test.jpg"); 10 Mat logo = imread("logo.jpg"); 11 12 //设定ROI区域 13 Mat ROI = src(Rect(20, 25, logo.cols, logo.rows));//注意这边Rect函数,先列后行(长*高(宽)) 14 imshow("原始ROI", ROI); 15 16 //用logo的图像矩阵替换掉ROI区域的数据 17 logo.copyTo(ROI); 18 19 imshow("后来ROI", ROI); 20 imshow("src", src); 21 22 waitKey(0); 23 return 0; 24 25 }
1 #include <opencv2/opencv.hpp> 2 #include <iostream> 3 4 using namespace cv; 5 using namespace std; 6 7 int main(int argc, char** argv) 8 { 9 Mat src = imread("test.jpg"); 10 Mat logo = imread("logo.jpg"); 11 12 //设定ROI区域 13 Mat ROI = src(Rect(20, 25, logo.cols, logo.rows));//注意这边Rect函数,先列后行(长*高(宽)) 14 imshow("ROI", ROI); 15 16 addWeighted(ROI,1, logo, 0.1, 0., ROI,-1);//两张图片必须大小相同 17 imshow("src", src); 18 19 waitKey(0); 20 return 0; 21 22 }
1 #include <opencv2/opencv.hpp> 2 #include <iostream> 3 4 using namespace cv; 5 using namespace std; 6 7 int main(int argc, char** argv) 8 { 9 Mat src = imread("test.jpg"); 10 Mat ROI; 11 vector<Mat> channls; 12 split(src, channls); 13 ROI = channls.at(0); 14 15 imshow("ROI", ROI); 16 imshow("src", src); 17 18 waitKey(0); 19 return 0; 20 21 }
1 #include <opencv2/opencv.hpp> 2 #include <iostream> 3 4 using namespace cv; 5 using namespace std; 6 7 int main(int argc, char** argv) 8 { 9 Mat src = imread("test.jpg"); 10 Mat Red,Green,Blue,dst; 11 vector<Mat> channls; 12 split(src, channls); 13 Blue = channls.at(0); 14 Green = channls.at(0); 15 Red = channls.at(0); 16 17 imshow("Blue", Blue); 18 imshow("Green", Green); 19 imshow("Red", Red); 20 imshow("src", src); 21 22 merge(channls, dst); 23 imshow("dst", dst); 24 25 waitKey(0); 26 return 0; 27 28 }