opencv学习之路(4):图像的叠加,add、addweighted、‘+’
1、图像的叠加
#include <iostream> #include "opencv2/opencv.hpp" using namespace std; int main() { cv::Mat matImage1 = cv::imread("E:/QtMaterial/images/boldt.jpg"); cv::Mat matImage2 = cv::imread("E:/QtMaterial/images/rain.jpg"); cv::Mat result; float flag,k1,k2,k3; while(flag != 9) { cout<<"c[i]=k1*a[i]+k2*b[i]+k3"<<endl; cout<<"flag k1 k2 k3"<<endl; cin>>flag>>k1>>k2>>k3; // cv::addWeighted(matImage1,k1,matImage2,k2,k3,result); result = k1*matImage1+k2*matImage2+k3; cv::imshow("Process",result); cv::waitKey(); cv::destroyWindow("Process"); } return 0; }
代码2,vector<cv::Mat>planes;split,merge
#include <iostream> #include "opencv2/opencv.hpp" using namespace std; int main() { cv::Mat matImage1 = cv::imread("E:/QtMaterial/images/boldt.jpg"); cv::Mat matImage2 = cv::imread("E:/QtMaterial/images/rain.jpg",0); std::vector<cv::Mat>planes; cv::Mat result; float flag=0,k1,k2,k3; uchar k; while(flag != 9) { cout<<"flag"<<endl; cin>>flag; if(flag==1){ cout<<"c[i]=k1*a[i]+k2*b[i]+k3"<<endl; cout<<"k1 k2 k3"<<endl; cin>>k1>>k2>>k3; // cv::addWeighted(matImage1,k1,matImage2,k2,k3,result); result = k1*matImage1+k2*matImage2+k3; cv::imshow("Process1",result); cv::waitKey(); cv::destroyWindow("Process1"); } if(flag ==2) { cout<<"k"<<endl; cin>>k; cv::split(matImage1,planes); planes[k-'0']+=matImage2; cv::merge(planes,result); cv::imshow("Process2",result); cv::waitKey(); cv::destroyWindow("Process2"); } } return 0; }