opencv bitwise_and bitwise_or bitwise_not

图像处理的这三个函数,我是记了忘,忘了记。网上一大片都说这三个函数针对二值图像,但是我依稀记得并不是,下面说明实验结果:

#include
#include

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(10, 10) << endl;
    cout << "or" << (int)dst.at(10, 10) << endl;
    cout << "src" << (int)srcimg1.at(10, 10) << endl;
    cout << "M" << (int)M.at(10, 10) << endl;

    waitKey();
}

上面是代码。
首先是原图:
opencv bitwise_and bitwise_or bitwise_not_第1张图片
然后是模板图:
opencv bitwise_and bitwise_or bitwise_not_第2张图片
然后是这两张图的bitwise_and:
opencv bitwise_and bitwise_or bitwise_not_第3张图片
再然后是bitwise_or:
opencv bitwise_and bitwise_or bitwise_not_第4张图片
最后分别取每幅图的第(10,10)个像素点进行验证:
这里写图片描述
60与125的像素值相与后是60,相或后是125。以上结果能够说明很多事情。

你可能感兴趣的:(opencv)