第六天:圖像的基本運算

圖像本質來說就是一個矩陣,所以圖像的基本運算與矩陣的運算基本雷同。

eg:

#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;

void main()
{
	Mat img1 = imread("1.jpg");
	Mat img2 = imread("2.jpg");
	Mat dst;  //存儲結果
	imshow("img1", img1);
	imshow("img2", img2);
	cout<<"img1  "<<int(img1.at<Vec3b>(10, 10)[0])<<endl;
	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 = img1 - img2; //減
	//subtract(img1, img2, dst);
	//absdiff(img1, img2, dst);

	//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); //異或

	cout<<"dst  "<<int(dst.at<Vec3b>(10, 10)[0])<<endl;
	imshow("dst", dst);
	waitKey(0);

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章