效果

项目

VS2010+.net4.0+OpenCvSharp3

代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Drawing2D;
using OpenCvSharp;
using OpenCvSharp.Extensions;namespace OpenCvSharp_去水印
{public partial class Form1 : Form{public Form1(){InitializeComponent();}bool IsDraw;System.Drawing.Point StartPoint, EndPoint;Pen p = new Pen(Color.Red, 2);Bitmap originImg;Image finishImg;Pen pen = new Pen(Color.Red, 2);public System.Drawing.Point[] pt = new System.Drawing.Point[4];Font font = new Font("宋体", 12);SolidBrush solidBrush = new SolidBrush(Color.Red);Rectangle rect;Graphics g;Bitmap bmp;string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string img = "";Mat src;Mat maskROI;Mat mask;Mat dst = new Mat();Rect roiRect;private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;img = ofd.FileName;var imagebyte = File.ReadAllBytes(img);bmp = new Bitmap(img);pictureBox1.Image = bmp;src = new Mat(img);g = pictureBox1.CreateGraphics();g.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高,即消除锯齿g.InterpolationMode = InterpolationMode.HighQualityBicubic;g.CompositingQuality = CompositingQuality.HighQuality;p.StartCap = LineCap.Square;p.EndCap = LineCap.Square;originImg = new Bitmap(img);finishImg = (Image)originImg.Clone();}private void button4_Click(object sender, EventArgs e){pictureBox1.Image = bmp;originImg = new Bitmap(img);finishImg = (Image)originImg.Clone();}/// <summary>/// 鼠标左键按下/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void pictureBox1_MouseDown(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){IsDraw = true;GetImagePixLocation(pictureBox1.Size, pictureBox1.Image.Size, e.Location, out StartPoint);}}/// <summary>/// 鼠标滑动/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void pictureBox1_MouseMove(object sender, MouseEventArgs e){if (IsDraw){GetImagePixLocation(pictureBox1.Size, pictureBox1.Image.Size, e.Location, out EndPoint);finishImg = (Image)originImg.Clone();g = Graphics.FromImage(finishImg);g.SmoothingMode = SmoothingMode.AntiAlias;System.Drawing.Point leftTop = new System.Drawing.Point(StartPoint.X, StartPoint.Y);int width = Math.Abs(StartPoint.X - EndPoint.X), height = Math.Abs(StartPoint.Y - EndPoint.Y);if (EndPoint.X < StartPoint.X)leftTop.X = EndPoint.X;if (EndPoint.Y < StartPoint.Y)leftTop.Y = EndPoint.Y;rect = new Rectangle(leftTop, new System.Drawing.Size(width, height));g.DrawRectangle(p, rect);pictureBox1.Image = finishImg;}}private void GetImagePixLocation(System.Drawing.Size pictureBoxSize, System.Drawing.Size imageSize, System.Drawing.Point pictureBoxPoint, out System.Drawing.Point imagePoint){imagePoint = new System.Drawing.Point(0, 0);double scale;int detalInHeight = 0;int detalInWidth = 0;if (Convert.ToDouble(pictureBoxSize.Width) / pictureBoxSize.Height > Convert.ToDouble(imageSize.Width) / imageSize.Height){scale = 1.0 * imageSize.Height / pictureBoxSize.Height;detalInWidth = Convert.ToInt32((pictureBoxSize.Width * scale - imageSize.Width) / 2.0);}else{scale = 1.0 * imageSize.Width / pictureBoxSize.Width;detalInHeight = Convert.ToInt32((pictureBoxSize.Height * scale - imageSize.Height) / 2.0);}imagePoint.X = Convert.ToInt32(pictureBoxPoint.X * scale - detalInWidth);imagePoint.Y = Convert.ToInt32(pictureBoxPoint.Y * scale - detalInHeight);}/// <summary>/// 鼠标左键弹起/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void pictureBox1_MouseUp(object sender, MouseEventArgs e){IsDraw = false;originImg = (Bitmap)finishImg;pictureBox1.Image = originImg;}private void Form1_Load(object sender, EventArgs e){this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);this.UpdateStyles();//添加项:cBoxThresholdTypes.Items.Add(new ListItem("NS", InpaintMethod.NS));cBoxThresholdTypes.Items.Add(new ListItem("Telea", InpaintMethod.Telea));//设置选中项:cBoxThresholdTypes.SelectedIndex = 0;    //根据索引}private void button2_Click(object sender, EventArgs e){if (pictureBox1.Image == null ){return;}if (rect == null || (rect.Width==0 && rect.Height==0)){return;}maskROI = new Mat(rect.Height, rect.Width, src.Type(), Scalar.White);mask = src * 0;roiRect = new Rect(rect.X, rect.Y, rect.Width, rect.Height);mask[roiRect] = maskROI;Cv2.CvtColor(mask, mask, ColorConversionCodes.BGR2GRAY);if (pictureBox2.Image != null){pictureBox2.Image.Dispose();}pictureBox2.Image = BitmapConverter.ToBitmap(mask);}private void button3_Click(object sender, EventArgs e){Inpaint();}private void trackBar1_Scroll(object sender, EventArgs e){Inpaint();}InpaintMethod inpaintMethod;String CommandText = "";void Inpaint(){if (pictureBox1.Image == null || pictureBox2.Image == null){return;}if (rect == null || (rect.Width == 0 && rect.Height == 0)){return;}ListItem li = (ListItem)cBoxThresholdTypes.SelectedItem;inpaintMethod = (InpaintMethod)li.Value;CommandText = String.Format("Cv2.Inpaint(src, mask, dst,{0},{1})", trackBar1.Value, inpaintMethod.ToString());txtCommandText.Text = CommandText;Cv2.Inpaint(src, mask, dst, trackBar1.Value, inpaintMethod);if (pictureBox3.Image != null){pictureBox2.Image.Dispose();}pictureBox3.Image = BitmapConverter.ToBitmap(dst);}private void cBoxThresholdTypes_SelectedIndexChanged(object sender, EventArgs e){Inpaint();}}
}

Demo 下载​​​​​​​

C# OpenCvSharp 去水印 图像修复相关推荐

  1. 基于神经网络的图像去水印/图像修复实践

    采用的一个开源的用于生成图像修复的框架,主要基于 Contextual Attention (CVPR 2018)和 Gated Convolution (ICCV 2019 Oral) 作者源码地址 ...

  2. 使用Python,OpenCV进行去水印,图像修复

    图像修复是图像保存和图像恢复的一种形式,其历史可以追溯到1700年代,当时意大利威尼斯的公共图片修复总监彼得·爱德华兹(Pietro Edwards)应用这种科学方法来修复和保存著名作品(资料来源). ...

  3. 短视频去水印方法之-opencv进行批量图像修复

    目录 1. 新建并配置一个新的VS工程 2. 代码 3. 测试结果对比 环境:VS2019专业版(Microsoft Visual Studio Enterprise 2019) + opencv-3 ...

  4. OpenCV中图像修复技术介绍与演示

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自:opencv学堂 现实中图像经常出现划伤或者被噪声腐蚀或 ...

  5. 结构感知图像修复:ICCV2019论文解析

    结构感知图像修复:ICCV2019论文解析 StructureFlow: Image Inpainting via Structure-aware Appearance Flow 论文链接: http ...

  6. Python,OpenCV中的图像修复——cv2.inpaint()

    Python,OpenCV中的图像修复--cv2.inpaint 1. 效果图 2. 原理 3. 源码 参考 image inpainting 图像修改 这篇博客将介绍如何通过OpenCV中图像修复的 ...

  7. 利用OpenCV实现图像修复(含源码链接)

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 前一段时间小白分享过关于图像修复技术介绍的推文(点击可以跳转),有 ...

  8. 从暗通道先验去雾到海底图像修复-三维重建辅助计算摄影

    点击上方"小白学视觉",选择加"星标"或"置顶"重磅干货,第一时间送达 一. Sea Thru:海底图像修复 我想很多朋友一定看过海底的各种 ...

  9. 【OpenCV 4开发详解】图像修复

    本文首发于"小白学视觉"微信公众号,欢迎关注公众号 本文作者为小白,版权归人民邮电出版社发行所有,禁止转载,侵权必究! 经过几个月的努力,小白终于完成了市面上第一本OpenCV 4 ...

  10. python——图像处理3(均值偏移、改变亮度、图像修复、图像融合)

    https://blog.csdn.net/gm_ergou/article/details/92846396 1.均值偏移(磨皮效果) import cv2 as cv import numpy a ...

最新文章

  1. Delphi在创建和使用DLL的时候如果使用到string,请引入ShareMem单元
  2. 操作系统第四章-文件管理
  3. Linux深入理解Socket异常
  4. Springboot使用Log4j2的配置详解
  5. java 编译器重排序_Java编译器重新排序
  6. 2018年秋计算机应用基础本科,广东开放大学远程教育专科2018年秋计算机应用基础Word模块测试...
  7. mysql 事务 注意 优化_MySQL入门详解(二)---mysql事务、锁、以及优化
  8. 读书感悟之,从术到道
  9. Image的Stride
  10. 大型油烟机清洗机器人_餐饮业大型油烟机清洗的必要性,你知道吗?
  11. tx2使用远程开机后分辨率不正确
  12. “华硕zx50j,键盘背光灯无法显示,fn组合键不可用”解决办法
  13. C#中的Builder模式
  14. ember controller内调用save修改model数据时出现null的解决方案
  15. model.train()与model.eval()的用法
  16. HR 真的会嫌弃面试者跳槽频繁吗?
  17. Linux笔记:文本编辑器nano简单说明
  18. 如何提高云服务器性能,提高云服务器性能
  19. 信号与系统第一章--基本知识
  20. 杰奇cms mysql查询_杰奇cms自动推送链接插件使用方式

热门文章

  1. 我的世界php7枪械插件,[娱乐|机制|其他]Myitem--超强RPG武器制作插件[1.8-1.12]]
  2. RedisCluster集群之动态增删节点
  3. ZT 绿茶和枸杞绝不可以同饮
  4. win10/11安裝時 OOBE強制跳過登入Microsoft賬戶
  5. 单词快速记忆day16
  6. Python3入门机器学习(四)- kNN算法的学习与使用
  7. 树莓派pip换国内源:解决换源后仍使用国内源的问题,亲测有效
  8. 彻头彻尾理解 LinkedHashMap
  9. 汽车芯片迅速发展产业链
  10. 验证码的创建(个人见解)