OpenCV笔记(6) Bitwise
源码:
-
BitwiseAnd
//dst = src1 & src2
public static void BitwiseAnd(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = null);
是对二进制数据进行“与”操作,即对图像(灰度图像或彩色图像均可)每个像素值进行二进制“与”操作,1&1=1,1&0=0,0&1=0,0&0=0
-
BitwiseNot
//dst = ~src public static void BitwiseNot(InputArray src, OutputArray dst, InputArray mask = null);
是对二进制数据进行“非”操作,即对图像(灰度图像或彩色图像均可)每个像素值进行二进制“非”操作,~1=0,~0=1
-
BitwiseOr
//computes bitwise disjunction of the two arrays (dst = src1 | src2) public static void BitwiseOr(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = null);
是对二进制数据进行“或”操作,即对图像(灰度图像或彩色图像均可)每个像素值进行二进制“或”操作,1|1=1,1|0=0,0|1=0,0|0=0
-
BitwiseXor
// computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2) public static void BitwiseXor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = null);
是对二进制数据进行“异或”操作,即对图像(灰度图像或彩色图像均可)每个像素值进行二进制“异或”操作,1^1=0,1^0=1,0^1=1,0^0=0
示例:
using System; using OpenCvSharp; namespace ConsoleApp2 { class Program { static void Main(string[] args) { Mat dst = new Mat(); Mat mask_not = new Mat(); Mat img = Cv2.ImRead("C:\\Users\\ATWER\\Desktop\\d.png"); Cv2.CvtColor(img, img, ColorConversionCodes.BGR2GRAY); Mat mask = new Mat(img.Rows, img.Cols, MatType.CV_8UC1,new Scalar(255)); Cv2.Rectangle(mask, new Rect(50, 50, 100, 150), new Scalar(0),-1); Cv2.BitwiseNot(mask, mask_not); Cv2.BitwiseAnd(img, mask_not, dst); Cv2.ImShow("img", img); Cv2.ImShow("mask", mask); Cv2.ImShow("mask_not", mask_not); Cv2.ImShow("dst", dst); Cv2.WaitKey(0); } } }
结果: