第六天:图像的基本运算

来源:互联网 发布:知乎电子书 编辑:程序博客网 时间:2024/06/11 16:42

图像本质来说就是一个矩阵,所以图像的基本运算与矩阵的运算基本雷同。

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);}