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"
  • 相关阅读:
    const char * 和 std::string.c_str()是个危险的东西!
    原先360商店有msnlite这个软件,后来估计因为被小米收购的原因下架了
    C++ Notes: Table of Contents
    强烈推荐:C++ manpages C++函数查询文档_Dasm_百度空间
    爱上MVC3~实体级标准验证
    Js+MVC~公用API的设计,返回jsonp后使ajax的error属性生效!
    爱上MVC3系列~PartialView()与View()真的一样吗?
    Js~对Boxy弹出框进行封装,提供弹出后自动隐藏与自动跳转功能
    爱上MVC3系列~手动向路由表扔数据,不影响当前URL路由配对
    c# webservice生成客户端及使用时碰到decimal类型时的特殊处理
  • 原文地址:https://www.cnblogs.com/Vince-Wu/p/11114800.html
Copyright © 2011-2022 走看看