1.加载图像
1 #include<opencv.hpp> 2 using namespace cv; 3 int main() 4 { 5 Mat a = imread("E:/test.jpg"); 6 imshow("picture", a); 7 waitKey(); 8 return 0; 9 }
2.图像融合
1 #include<opencv2/opencv.hpp> 2 #include<opencv2/core/core.hpp> 3 #include<opencv2/highgui/highgui.hpp> 4 5 using namespace cv; 6 using namespace std; 7 8 int main() 9 { 10 Mat background = imread("E:/test.jpg"); 11 12 Mat logo = imread("E:/logo.jpg"); 13 14 Mat imageROI=background(Rect(100, 100, logo.cols, logo.rows)); //在background上定义感性区域 15 16 addWeighted(imageROI, 0.5, logo, 0.3, 0., imageROI); //融合,将logo融合到ROI上,保存为ROI 17 18 waitKey(); 19 return 0; 20 }
3.分通道
1 #include<iostream> 2 #include<vector> 3 #include<opencv2/opencv.hpp> 4 using namespace std; 5 using namespace cv; 6 int main3() 7 { 8 Mat src = imread("E:/test.jpg"); 9 imshow("src", src); 10 vector<Mat> channels; 11 split(src, channels); 12 13 Mat blue, green, red; 14 blue = channels.at(0); 15 green= channels.at(1); 16 red= channels.at(2); 17 imshow("blue", blue); 18 imshow("green", green); 19 imshow("red", red); 20 21 waitKey(); 22 return 0; 23 }
合并
1 Mat dst; 2 merge(channels, dst); 3 imshow("dst", dst);