参考c++博客: https://www.cnblogs.com/little-monkey/p/7202628.html
本文大部分来自c++博客,少量修改
如果有什么问题请到(0)这编博客去反馈,查看每一遍博客太麻烦了:
火山opencv学习之路(0)、前期准备,博客列表,问题收集-利快云博客阅读 /ArticleForumInsidePage?page=1&id=16397428350715870
嵌入代码不知道怎么用?先看看下面博客:
火山opencv学习之路(1)封装编、示例程序-利快云博客阅读 /ArticleForumInsidePage?page=1&id=16397674806938428
@ using namespace cv;
@ using namespace std;
@ Mat img1=imread(GetMbsText(@<文件名>.GetText(), CVolMem(), NULL));
@ Mat img2=imread(GetMbsText(@<文件名2>.GetText(), CVolMem(), NULL));
@ Mat dst;//存储结果
@ imshow("img1",img1); @ imshow("img2",img2); @ cout<<"img1 "<<int(img1.at<Vec3b>(10,10)[0])<<endl;//img1在坐标(10,10)的蓝色通道的值,强制转成int @ cout<<"img2 "<<int(img2.at<Vec3b>(10,10)[0])<<endl; @ @ dst=img1+img2;//这两个加法效果相同 @ //add(img1,img2,dst);//注意:这两个加法要求被加的图片尺寸必须一致 @ //addWeighted(img1,0.5,img2,0.5,0,dst);//按权重相加,下一行dst输出参数为正常参数的一半 @ cout<<"dst "<<int(dst.at<Vec3b>(10,10)[0])<<endl; @ imshow("dst",dst); @ waitKey(0);
两幅图的(10,10)处蓝色通道值相加大于了255,所以dst值为255,我们换一个小一点的坐标(420,420)试试
@ using namespace cv; @ using namespace std; @ @ Mat img1=imread(GetMbsText(@<文件名>.GetText(), CVolMem(), NULL)); @ Mat img2=imread(GetMbsText(@<文件名2>.GetText(), CVolMem(), NULL)); @ Mat dst;//存储结果 @ imshow("img1",img1); @ imshow("img2",img2); @ cout<<"img1 "<<int(img1.at<Vec3b>(10,10)[0])<<endl;//img1在坐标(10,10)的蓝色通道的值,强制转成int @ cout<<"img2 "<<int(img2.at<Vec3b>(10,10)[0])<<endl; @ //dst=img1-img2;//这两个减法效果相同 若dst<0,则dst=0
@ //subtract(img1,img2,dst);//注意:要求被处理图片尺寸一致 @ absdiff(img1,img2,dst);//若dst<0,则dst=|dst|>=0 用于检测两幅相似图像的不同点,效果比上面的两种减法好 @ cout<<"dst "<<int(dst.at<Vec3b>(10,10)[0])<<endl; @ imshow("dst",dst); @ waitKey(0);
@ dst=5*img1;//增加曝光 @ dst=img1/5;//降低曝光 @ bitwise_and(img1,img2,dst);//逻辑与,求交集 @ bitwise_or(img1,img2,dst);//逻辑或,求并集 @ bitwise_not(img1,dst);//逻辑非,求补集 @ bitwise_xor(img1,img2,dst);//异或,相同为0,相异为1
Copyright © 2022 资源站 - All rights reserved