图像处理的这三个函数,我是记了忘,忘了记。网上一大片都说这三个函数针对二值图像,但是我依稀记得并不是,下面说明实验结果:
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
Mat srcimg1 = imread("C:\\Users\\dushuang\\Desktop\\lotsfiles\\bhs\\3.jpg", 0);
Mat gray = srcimg1;
Mat M(gray.rows, gray.cols, CV_8UC1, Scalar(60));
Mat N(gray.size(), CV_8UC1, Scalar(255));
Mat dst;
Mat dst1;
imshow("srcimg1", srcimg1);
bitwise_and(srcimg1,M, dst);
bitwise_or(srcimg1, M, dst1);
imshow("and", dst);
imshow("or", dst1);
imshow("M", M);
cout << "and" << (int)dst.at<uchar>(10, 10) << endl;
cout << "or" << (int)dst.at<uchar>(10, 10) << endl;
cout << "src" << (int)srcimg1.at<uchar>(10, 10) << endl;
cout << "M" << (int)M.at<uchar>(10, 10) << endl;
waitKey();
}
上面是代码。
首先是原图:
然后是模板图:
然后是这两张图的bitwise_and:
再然后是bitwise_or:
最后分别取每幅图的第(10,10)个像素点进行验证:
60与125的像素值相与后是60,相或后是125。以上结果能够说明很多事情。