c# OpenCvSharp 按位运算 BitwiseAnd BitwiseOr BitwiseXor BitwiseNot

c# OpenCvSharp 按位运算 BitwiseAnd BitwiseOr BitwiseXor BitwiseNot

using OpenCvSharp;
using OpenCvSharp.Extensions;
using DlibDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace app
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 按位运算
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBitwise_Click(object sender, EventArgs e)
        {
            Mat src1 = Cv2.ImRead(@"img\bitwise0.png");
            Mat src2 = Cv2.ImRead(@"img\bitwise1.png");
            Mat dest_bitwise_and = new Mat();
            Mat dest_bitwise_or = new Mat();
            Mat dest_bitwise_xor = new Mat();
            Mat dest_bitwise_not = new Mat();

            // 按位运算
            Cv2.BitwiseAnd(src1, src2, dest_bitwise_and);  // 与运算操作就是1 & 1 = 1, 其他为0。
            Cv2.BitwiseOr(src1, src2, dest_bitwise_or);    // 或运算 0 | 0 = 0, 其他为1。
            Cv2.BitwiseXor(src1, src2, dest_bitwise_xor);  // 异或运算就是相同为0,不同为1,也就是 0 ^ 0 = 0 , 1 ^ 1 = 0 , 另外2个为1。
            Cv2.BitwiseNot(src1, dest_bitwise_not);        // opencv非运算不是1变0,0变1。而是 !x = 255 - x

            Cv2.ImShow("原图1", src1);
            Cv2.ImShow("原图2", src2);
            Cv2.ImShow("BitwiseAnd", dest_bitwise_and);
            Cv2.ImShow("BitwiseOr", dest_bitwise_or);
            Cv2.ImShow("BitwiseXor", dest_bitwise_xor);
            Cv2.ImShow("BitwiseNot", dest_bitwise_not);
        }
    }
}

 

 

发表回复

您的电子邮箱地址不会被公开。