图片减法可以用于:
零件的缺陷检测。
#include"opencv2/opencv.hpp"
#include<iostream>
using namespace cv;
using namespace std;
void main()
{
Mat img1 = imread("1.jpg");
Mat img2 = imread("5.jpg");
Mat dst;
//subtract(img1,img2,dst);//小的减去大的,负数不变
absdiff(img1,img2,dst);//|小的减去大的|,负数的绝对值
imshow("img1",img1);
imshow("img5",img2);
imshow("dst",dst);
//输出坐标(10,10)的蓝色通道的像素值
cout << "img1:" <<int(img1.at<Vec3b>(10, 10)[0]) << endl;//Vec3b是一种短向量的数据类型(3通道uchar类型的矩阵)
cout << "img5:" <<int(img2.at<Vec3b>(10, 10)[0])<< endl;
cout << "dst:" <<int(dst.at<Vec3b>(10, 10)[0]) << endl;
waitKey(0);
}