|
opencvsharp,二值化方法,注意含义。
类型 | >thresh | <=thresh | THRESH_BINARY | maxval | 0 | THRESH_BINARY_INV | 0 | maxval | THRESH_TRUNC | thresh | src | THRESH_TOZERO | src | 0 | THRESH_TOZERO_INV | 0 | src |
- Mat img1 = Cv2.ImRead("D:/dd.png ");
- Mat img2 = Cv2.ImRead("D:/ss.png");
- Mat ROIs = new Mat(img2.Height, img2.Width, MatType.CV_8UC3, Scalar.All(255));
- Rect Roi = new Rect(0, 0, img2.Width, img2.Height);
- img1[Roi].CopyTo(ROIs);
- Mat img2gray = new Mat(img2.Height, img2.Width, MatType.CV_8UC1, Scalar.All(255));
- Cv2.CvtColor(img2, img2gray, ColorConversionCodes.BGR2GRAY);
- Mat mask = new Mat();
- Cv2.Threshold(img2gray, mask, 200, 255, ThresholdTypes.Binary);
- Mat mask_inv = new Mat();
- Cv2.BitwiseNot(mask, mask_inv);
- Mat img1_bg = new Mat();
- Cv2.BitwiseAnd(ROIs, img2, img1_bg, mask);
- Mat dst = new Mat();
- Cv2.BitwiseAnd(img2, img2, dst, mask_inv);
- Mat dst2 = new Mat();
- Cv2.Add(img1_bg, dst, dst2);
- dst2.CopyTo(img1[Roi]);
- Cv2.ImShow("mask", mask);
- Cv2.ImShow("mask_inv", mask_inv);
- Cv2.ImShow("img1_bg", img1_bg);
- Cv2.ImShow("dst", dst);
- Cv2.ImShow("img1", img1);
- Cv2.ImShow("img2", img2);
- //Mat src_mask = 255 * Mat.Ones(src.Size(), MatType.CV_8U);
- //OpenCvSharp.Point center = new OpenCvSharp.Point(dst.Cols / 2, dst.Rows / 2);
- //Mat normal_clone = new Mat();
- //Mat mixed_clone = new Mat();
- //Cv2.SeamlessClone(src, dst, src_mask, center, normal_clone, SeamlessCloneMethods.NormalClone);
- //Cv2.SeamlessClone(src, dst, src_mask, center, mixed_clone, SeamlessCloneMethods.MixedClone);
- //Cv2.ImShow("ROI_img", src);
- //Cv2.ImShow("bg_img", dst);
- //Cv2.ImShow("normal_clone", normal_clone);
- //Cv2.ImShow("mixed_clone", mixed_clone);
- Cv2.WaitKey(0);
复制代码
参考:
【1】使用C#winform和opencvsharp做一个小软件
【2】OpenCV3-Python常用轮廓检测方法
【3】Opencv学习笔记 OpencvSharp寻找并绘制最小外接圆
【4】opencv知道四个顶点的坐标,截取ROI(C++/opencv3.1)(和C#OpencvSharp版本)
【5】使用Opencvsharp进行图像旋转矫正截取兴趣区域
【6】OpenCV学习——轮廓检测https://blog.csdn.net/zb1165048017/article/details/109404373
【7】基于OpenCvSharp的数字图像处理 - 二值化
【8】OpenCVSharp学习之模板匹配
【9】OpenCvSharp 学习笔记7 --绘制图形和文字
【10】OpencvSharp图像融合
【11】opencv 实现图像融合
【12】OpenCV之bitwise_and、bitwise_not等图像基本运算及掩膜
【13】OpenCV 中BoundingRect、minAreaRect的用法区别
|
|