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"
  • 相关阅读:
    SVN还原项目到某一版本(转)
    C# Web Service 不使用服务引用直接调用方法(转)
    动态调用webservice时 ServiceDescriptionImporter类在vs2010无法引用的解决方法 (转)
    log4net示例2-日志输入存入Access(转)
    C# log4net 配置及使用详解--日志保存到文件和Access(转)
    未能解析引用的程序集......因为它对不在当前目标框架“.NETFramework,Version=v4.0,Profile=Client”中的 (转)
    Hello log4net——做一个实用好用的log4net的demo(转)
    JS移动客户端--触屏滑动事件
    js生成二维码实例
    触屏版类似刷新页面文本框获取焦点的同时弹出手机键盘的做法
  • 原文地址:https://www.cnblogs.com/Vince-Wu/p/11114800.html
Copyright © 2011-2022 走看看