加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

opencv基本图像运算——加减与或

(2019-06-08 18:44:55)
分类: openmv/opencv
 1 #include
 2 #include
 3 using namespace cv;
 4 using namespace std;
 5 
 6 void main(){
 7     Mat img1=imread("E://1.jpg");
 8     Mat img2=imread("E://2.jpg");
 9     Mat dst;//存储结果
10     imshow("img1",img1);
11     imshow("img2",img2);
12     cout<<"img1  "<<int(img1.at(10,10)[0])<<endl;//img1在坐标(10,10)的蓝色通道的值,强制转成int
13     cout<<"img2  "<<int(img2.at(10,10)[0])<<endl;
14 
15     dst=img1+img2;//这两个加法效果相同
16     //add(img1,img2,dst);//注意:这两个加法要求被加的图片尺寸必须一致
17     //addWeighted(img1,0.5,img2,0.5,0,dst);//按权重相加,下一行dst输出参数为正常参数的一半
18     cout<<"dst  "<<int(dst.at(10,10)[0])<<endl;
19     imshow("dst",dst);
20     waitKey(0);
21 }

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170718201141115-1069369529.png

两幅图的(10,10)处蓝色通道值相加大于了255,所以dst值为255,我们换一个小一点的坐标(420,420)试试

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170718201426818-2051751656.png

二、图像减法

 1 #include
 2 #include
 3 using namespace cv;
 4 using namespace std;
 5 
 6 void main(){
 7     Mat img1=imread("E://1.jpg");
 8     Mat img2=imread("E://5.jpg");
 9     Mat dst;//存储结果
10     imshow("img1",img1);
11     imshow("img2",img2);
12     cout<<"img1  "<<int(img1.at(10,10)[0])<<endl;//img1在坐标(10,10)的蓝色通道的值,强制转成int
13     cout<<"img2  "<<int(img2.at(10,10)[0])<<endl;
14 
15     //dst=img1-img2;//这两个减法效果相同    若dst<0,则dst=0
16     //subtract(img1,img2,dst);//注意:要求被处理图片尺寸一致
17     absdiff(img1,img2,dst);//若dst<0,则dst=|dst|>=0    用于检测两幅相似图像的不同点,效果比上面的两种减法好
18     cout<<"dst  "<<int(dst.at(10,10)[0])<<endl;
19     imshow("dst",dst);
20     waitKey(0);
21 }

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170718204825536-155566821.png

 三、乘除与或非

1     dst=5*img1;//增加曝光
2     dst=img1/5;//降低曝光
3     bitwise_and(img1,img2,dst);//逻辑与,求交集
4     bitwise_or(img1,img2,dst);//逻辑或,求并集
5     bitwise_not(img1,dst);//逻辑非,求补集
6     bitwise_xor(img1,img2,dst);//异或,相同为0,相异为1    

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170719105145021-652036627.png

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170719105200755-1919904404.png

 

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170719105213833-1221331798.png

https://images2015.cnblogs.com/blog/1199089/201707/1199089-20170719105235661-330464149.png

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有