zoukankan      html  css  js  c++  java
  • OpenCv 007---像素操作的逻辑操作

    1 所用到的主要OpenCv API

    /** @brief 逻辑与

    @param src1 first input array or a scalar.

    @param src2 second input array or a scalar.

    @param dst output array that has the same size and type as the input arrays.

    @param mask optional operation mask, 8-bit single channel array, that
    specifies elements of the output array to be changed.
    */

    CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
                                 OutputArray dst, InputArray mask = noArray());

    /** @brief 逻辑或

    @param src1 first input array or a scalar.
    @param src2 second input array or a scalar.
    @param dst output array that has the same size and type as the input arrays.
    @param mask optional operation mask, 8-bit single channel array, that
    specifies elements of the output array to be changed.
    */

    CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
                                 OutputArray dst, InputArray mask = noArray());

    /** @brief 逻辑异或

    @param src1 first input array or a scalar.
    @param src2 second input array or a scalar.
    @param dst output array that has the same size and type as the input arrays.
    @param mask optional operation mask, 8-bit single channel array, that
    specifies elements of the output array to be changed.
    */

    CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
                                 OutputArray dst, InputArray mask = noArray());

    /** @brief Inverts every bit of an array.取反

    @param src input array.
    @param dst output array that has the same size and type as the input
    array.
    @param mask optional operation mask, 8-bit single channel array, that
    specifies elements of the output array to be changed.
    */

    CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
                                  InputArray mask = noArray());

    2 程序代码

    #include "opencv2opencv.hpp"
    #include <iostream>
    
    using namespace std;
    using namespace cv;
    
    int main(int argc, char *argv[])
    {
        //创建图片1
        Mat src1 = Mat::zeros(Size(400, 400), CV_8UC3);
        Rect rect(100, 100, 100, 100);
        src1(rect) = Scalar(0, 0, 255);//bgr
        imshow("input1",src1);
        printf("创建第一张图片...
    ");
    
        //创建图片2
        Mat src2 = Mat::zeros(Size(400, 400), CV_8UC3);
        rect.x = 150;
        rect.y = 150;
        src2(rect) = Scalar(0, 0, 255);//bgr
        imshow("input2", src2);
        printf("创建第二张图片...
    ");
    
            //取反操作
        Mat src = imread("G:\CVworkstudy\program_wwx\研习社140课时\ZhaiZhigang140\lena.jpg");
        imshow("input", src);
        Mat dst;
        bitwise_not(src, dst);
        //逻辑操作
        Mat dst1, dst2, dst3;
        bitwise_and(src1,src2,dst1);
        bitwise_or(src1, src2, dst2);
        bitwise_xor(src1, src2, dst3);
        
        
        //结果显示
        imshow("取反操作", dst);
        imshow("逻辑与", dst1);
        imshow("逻辑或", dst2);
        imshow("逻辑异或", dst3);
    
        waitKey(0);
        return 0;
    }

    3 运行结果

    One day,I will say "I did it"
  • 相关阅读:
    关于三次握手与四次挥手你要知道这些
    seafile看不见repo报500错误的解决方法
    VMWare Workstation 配置docker多macvlan网络方法
    利用Python3的dpkt库进行ARP扫描
    关于LAMP配置Let’s Encrypt SSL证书
    OpenSSL生成CA证书及终端用户证书
    CentOS7.2安装Vim8和YouCompleteMe
    CentOS 7.2安装Jenkins自动构建Git项目
    CentOS 7.2 安装Gerrit 2.14.6
    CentOS7.2编译GCC7.3
  • 原文地址:https://www.cnblogs.com/Vince-Wu/p/11114800.html
Copyright © 2011-2022 走看看