OpenCv 图像加减运算

#include <iostream>
#include <opencv2\opencv.hpp>

using namespace std;
using namespace cv;

#define wise//subtract//add
int main()
{
    //std::cout << "Hello World!\n"; 
	Mat img1=imread("E:/test/MySource/OpenCV/1.jpg");
	Mat img2 = imread("E:/test/MySource/OpenCV/2.jpg");

	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;

#ifdef  add
	dst = img2 + img1;//两图相加
	//add(img1,img2,dst);//注意:这两个加法要求被加的图片尺寸必须一直
	//addWeighted(img1,0.5,im2,0.5,0,dst);//按权重相加,下一行dst输出参数为正常参数的一般
	cout << "dst " << int(dst.at<Vec3b>(10, 10)[0]) << endl;
	
#endif //  add


#ifdef subtract
	//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;

#endif // subtract

#ifdef wise
	dst = 5 * img1;//增加曝光
	imshow("增加曝光", dst);
	dst = img1 / 5;//降低曝光
	imshow("降低曝光", dst);

	bitwise_and(img1, img2, dst);//逻辑与,求交集
	imshow("逻辑与", dst);
	bitwise_or(img1, img2, dst);//逻辑或,求并集
	imshow("逻辑或", dst);
	bitwise_not(img1, dst);//逻辑非,求补集
	imshow("逻辑非", dst);
	bitwise_xor(img1, img2, dst);//亦或,相同为0 相异为1
	imshow("亦或", dst);
#endif // wise


	imshow("dst", dst);
	waitKey(0);
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值