• 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"
  • 相关阅读:
    Caliburn Micro 框架 WP8使用研究(二)页面导航
    Windows Phone 8 Fast Resume 快速恢复浅析(二)
    Caliburn Micro 框架 WP8使用研究(一)简介
    当BI迈入云端,分析云为我们带来了什么?
    解读SQL Server 2012中的最新BI功能
    一个典型的BI系统介绍
    SQL Server数据库服务器的负载均衡集群实现方法
    Web数据挖掘在电子商务中的应用
    2012商业智能发展趋势预测
    一个商业智能培训经理眼中的商业智能
  • 原文地址:https://www.cnblogs.com/Vince-Wu/p/11114800.html
Copyright © 2020-2023  润新知