C# OpenCvSharp 去水印 图像修复.rar

C# OpenCvSharp 去水印 图像修复.rar

38.05MBRAR

C# OpenCvSharp 去水印 图像修复.rar

完整Demo,可直接运行

项目

VS2022+.net4.8+OpenCvSharp4

代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Security.Cryptography;

using System.Text;

using System.Windows.Forms;

using OpenCvSharp;

using OpenCvSharp.Extensions;

namespace OpenCvSharp_去水印_图像修复

{

  public partial class Form1 : Form

  {

    public Form1()

    {

      InitializeComponent();

    }

    Bitmap bmp;

    string fileFilter = “*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png”;

    string imgPath = “”;

    public Mat img, img0, inpainted, inpaintMask;

    int thickness = 10;

    string CommandText;

    InpaintMethod inpaintMethod;

    ListItem li;

    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 trackBar2_Scroll(object sender, EventArgs e)

    {

      thickness = trackBar2.Value;

    }

    private void button1_Click(object sender, EventArgs e)

    {

      OpenFileDialog ofd = new OpenFileDialog();

      ofd.Filter = fileFilter;

      if (ofd.ShowDialog() != DialogResult.OK) return;

      imgPath = ofd.FileName;

      bmp = new Bitmap(imgPath);

      pictureBox1.Image = bmp;

      img0 = Cv2.ImRead(imgPath);

      inpaintMask = new Mat(img0.Size(), MatType.CV_8U, Scalar.Black);

      pictureBox2.Image = BitmapConverter.ToBitmap(inpaintMask);

      pictureBox3.Image = null;

    }

    private void cBoxThresholdTypes_SelectedIndexChanged(object sender, EventArgs e)

    {

      Inpaint();

    }

    private void trackBar1_Scroll(object sender, EventArgs e)

    {

      Inpaint();

    }

    private void button4_Click(object sender, EventArgs e)

    {

      if (pictureBox1.Image == null)

      {

        return;

      }

      img = img0.Clone();

      inpaintMask = new Mat(img0.Size(), MatType.CV_8U, Scalar.Black);

      inpainted = img0.EmptyClone();

      Window wImage = new Window(“image”, img);

      OpenCvSharp.Point prevPt = new OpenCvSharp.Point(-1, -1);

      wImage.SetMouseCallback((MouseEventTypes ev, int x, int y, MouseEventFlags flags, IntPtr userdata) =>

      {

        if (ev == MouseEventTypes.LButtonUp || (flags & MouseEventFlags.LButton) == 0)

        {

          prevPt = new OpenCvSharp.Point(-1, -1);

        }

        else if (ev == MouseEventTypes.LButtonDown)

        {

          prevPt = new OpenCvSharp.Point(x, y);

        }

        else if (ev == MouseEventTypes.MouseMove && (flags & MouseEventFlags.LButton) != 0)

        {

          OpenCvSharp.Point pt = new OpenCvSharp.Point(x, y);

          if (prevPt.X < 0)

          {

            prevPt = pt;

          }

          inpaintMask.Line(prevPt, pt, Scalar.White, thickness, LineTypes.AntiAlias, 0);

          pictureBox2.Image = BitmapConverter.ToBitmap(inpaintMask);

          img.Line(prevPt, pt, Scalar.White, thickness, LineTypes.AntiAlias, 0);

          prevPt = pt;

          wImage.ShowImage(img);

        }

      });

      try

      {

        for (; ; )

        {

          switch ((char)Window.WaitKey(0))

          {

            case (char)27:  // exit

              return;

            case ‘r’:

              inpaintMask.SetTo(Scalar.Black);

              pictureBox2.Image = BitmapConverter.ToBitmap(inpaintMask);

              img0.CopyTo(img);

              wImage.ShowImage(img);

              break;

            case ‘i’:

            case ‘\r’:

              Inpaint();

              break;

          }

        }

      }

      finally

      {

        Window.DestroyAllWindows();

      }

    }

    private void button3_Click(object sender, EventArgs e)

    {

      Inpaint();

    }

    void Inpaint()

    {

      if (pictureBox1.Image == null)

      {

        return;

      }

      li = (ListItem)cBoxThresholdTypes.SelectedItem;

      inpaintMethod = (InpaintMethod)li.Value;

      Cv2.Inpaint(img, inpaintMask, inpainted, trackBar1.Value, inpaintMethod);

      pictureBox3.Image = BitmapConverter.ToBitmap(inpainted);

      CommandText = String.Format(“Cv2.Inpaint(src, mask, dst,{0},{1})”, trackBar1.Value, inpaintMethod.ToString());

      txtCommandText.Text = CommandText;

    }

  }

}

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Security.Cryptography;

using System.Text;

using System.Windows.Forms;

using OpenCvSharp;

using OpenCvSharp.Extensions;

 

namespace OpenCvSharp_去水印_图像修复

{

  public partial class Form1 : Form

  {

    public Form1()

    {

      InitializeComponent();

    }

 

 

    Bitmap bmp;

    string fileFilter = “*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png”;

    string imgPath = “”;

    public Mat img, img0, inpainted, inpaintMask;

    int thickness = 10;

    string CommandText;

    InpaintMethod inpaintMethod;

    ListItem li;

 

    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 trackBar2_Scroll(object sender, EventArgs e)

    {

      thickness = trackBar2.Value;

    }

 

    private void button1_Click(object sender, EventArgs e)

    {

      OpenFileDialog ofd = new OpenFileDialog();

      ofd.Filter = fileFilter;

      if (ofd.ShowDialog() != DialogResult.OK) return;

      imgPath = ofd.FileName;

      bmp = new Bitmap(imgPath);

      pictureBox1.Image = bmp;

      img0 = Cv2.ImRead(imgPath);

      inpaintMask = new Mat(img0.Size(), MatType.CV_8U, Scalar.Black);

      pictureBox2.Image = BitmapConverter.ToBitmap(inpaintMask);

      pictureBox3.Image = null;

    }

 

    private void cBoxThresholdTypes_SelectedIndexChanged(object sender, EventArgs e)

    {

      Inpaint();

    }

 

    private void trackBar1_Scroll(object sender, EventArgs e)

    {

      Inpaint();

    }

 

    private void button4_Click(object sender, EventArgs e)

    {

      if (pictureBox1.Image == null)

      {

        return;

      }

 

      img = img0.Clone();

      inpaintMask = new Mat(img0.Size(), MatType.CV_8U, Scalar.Black);

      inpainted = img0.EmptyClone();

 

      Window wImage = new Window(“image”, img);

 

      OpenCvSharp.Point prevPt = new OpenCvSharp.Point(-1, -1);

      wImage.SetMouseCallback((MouseEventTypes ev, int x, int y, MouseEventFlags flags, IntPtr userdata) =>

      {

        if (ev == MouseEventTypes.LButtonUp || (flags & MouseEventFlags.LButton) == 0)

        {

          prevPt = new OpenCvSharp.Point(-1, -1);

        }

        else if (ev == MouseEventTypes.LButtonDown)

        {

          prevPt = new OpenCvSharp.Point(x, y);

        }

        else if (ev == MouseEventTypes.MouseMove && (flags & MouseEventFlags.LButton) != 0)

        {

          OpenCvSharp.Point pt = new OpenCvSharp.Point(x, y);

          if (prevPt.X < 0)

          {

            prevPt = pt;

          }

          inpaintMask.Line(prevPt, pt, Scalar.White, thickness, LineTypes.AntiAlias, 0);

          pictureBox2.Image = BitmapConverter.ToBitmap(inpaintMask);

          img.Line(prevPt, pt, Scalar.White, thickness, LineTypes.AntiAlias, 0);

          prevPt = pt;

          wImage.ShowImage(img);

        }

      });

 

      try

      {

        for (; ; )

        {

          switch ((char)Window.WaitKey(0))

          {

            case (char)27:  // exit

              return;

            case ‘r’:

              inpaintMask.SetTo(Scalar.Black);

              pictureBox2.Image = BitmapConverter.ToBitmap(inpaintMask);

              img0.CopyTo(img);

              wImage.ShowImage(img);

              break;

            case ‘i’:

            case ‘\r’:

              Inpaint();

              break;

          }

        }

      }

      finally

      {

 

        Window.DestroyAllWindows();

      }

    }

 

    private void button3_Click(object sender, EventArgs e)

    {

      Inpaint();

    }

 

    void Inpaint()

    {

      if (pictureBox1.Image == null)

      {

        return;

      }

 

      li = (ListItem)cBoxThresholdTypes.SelectedItem;

      inpaintMethod = (InpaintMethod)li.Value;

 

      Cv2.Inpaint(img, inpaintMask, inpainted, trackBar1.Value, inpaintMethod);

      pictureBox3.Image = BitmapConverter.ToBitmap(inpainted);

      CommandText = String.Format(“Cv2.Inpaint(src, mask, dst,{0},{1})”, trackBar1.Value, inpaintMethod.ToString());

      txtCommandText.Text = CommandText;

    }

  }

}

资源下载此资源下载价格为22.0金币,请先
资源下载
下载价格22.0 金币

资源声明(购买视为同意此声明):
1.在网站平台的任何操作视为已阅读和同意网站底部的注册协议及免责声明,本站资源已是超低价,且不提供技术支持
2.部分网络用户分享网盘地址有可能会失效,如发生失效情况请发邮件给客服code711cn#qq.com (把#换成@)会进行补发
3.本站站内提供的所有可下载资源(软件等等)本站保证未做任何负面改动;但本网站不能保证资源的准确性、安全性和完整性,用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都不是100%无错或无bug;需要您有一定的基础能够看懂代码,能够自行调试修改代码并解决报错。同时本站用户必须明白,源码便利店对提供下载的软件等不拥有任何权利,其版权归该资源的合法拥有者所有。
4.本站所有资源仅用于学习及研究使用,请必须在24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担
5.因资源可复制性,一旦购买均不退款,充值余额也不退款

充值送金币,用余额购买,低至6.7折!立即充值

显示验证码
没有账号? 注册  忘记密码?