• C# PaddleDetection yolo 印章检测


    目录

    效果

    项目

    代码

    下载 


    效果

    项目

    代码

    using OpenCvSharp;
    using OpenCvSharp.Extensions;
    using Sdcb.PaddleDetection;
    using Sdcb.PaddleInference;
    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;

    namespace PaddleDetection印章检测
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            Bitmap bmp;
            string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
            string img = "";

            double fontScale = 4D;
            int thickness = 4;
            LineTypes lineType = LineTypes.Link4;

            PaddleConfig paddleConfig;
            PaddleDetector d;
            String startupPath;
            float confidence = 0.90f;

            DateTime dt1 = DateTime.Now;
            DateTime dt2 = DateTime.Now;

            StringBuilder sb = new StringBuilder();

            private void Form1_Load(object sender, EventArgs e)
            {
                startupPath = Application.StartupPath;
                paddleConfig = PaddleConfig.FromModelDir(startupPath + "\\model\\");
                string configYmlPath = startupPath + "\\model\\infer_cfg.yml";
                d = new PaddleDetector(paddleConfig, configYmlPath, PaddleDevice.Mkldnn());
            }

            private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = fileFilter;
                if (ofd.ShowDialog() != DialogResult.OK) return;

                pictureBox1.Image = null;

                img = ofd.FileName;
                bmp = new Bitmap(img);
                pictureBox1.Image = new Bitmap(img);
                textBox1.Text = "";
            }

            private void button2_Click(object sender, EventArgs e)
            {
                if (img == "")
                {
                    return;
                }
                sb.Clear();
                Mat src = Cv2.ImRead(img);
                dt1 = DateTime.Now;
                DetectionResult[] r = d.Run(src);
                dt2 = DateTime.Now;
                Scalar scalar;

                for (int i = 0; i < r.Length; i++)
                {
                    if (r[i].Confidence > confidence)
                    {
                        scalar = Scalar.RandomColor();
                        Cv2.Rectangle(src, r[i].Rect, scalar, 4, LineTypes.Link8, 0);

                        Cv2.PutText(src, r[i].LabelName + "(" + r[i].Confidence + ")", new OpenCvSharp.Point(r[i].Rect.X + r[i].Rect.Width / 2, r[i].Rect.Y + r[i].Rect.Height / 2), HersheyFonts.HersheyComplex, fontScale, scalar, thickness, lineType, false);

                        sb.AppendLine(string.Format("{0}({1}) ({2},{3},{4},{5})",
                            r[i].LabelName
                            , r[i].Confidence
                            , r[i].Rect.Left
                            , r[i].Rect.Top
                            , r[i].Rect.Right
                            , r[i].Rect.Bottom
                            ));
                    }
                }

                sb.AppendLine("耗时:" + (dt2 - dt1).TotalMilliseconds + "ms");
                textBox1.Text = sb.ToString();

                pictureBox2.Image = BitmapConverter.ToBitmap(src);
            }
        }
    }
     

    1. using OpenCvSharp;
    2. using OpenCvSharp.Extensions;
    3. using Sdcb.PaddleDetection;
    4. using Sdcb.PaddleInference;
    5. using System;
    6. using System.Collections.Generic;
    7. using System.ComponentModel;
    8. using System.Data;
    9. using System.Drawing;
    10. using System.Linq;
    11. using System.Text;
    12. using System.Windows.Forms;
    13. namespace PaddleDetection印章检测
    14. {
    15. public partial class Form1 : Form
    16. {
    17. public Form1()
    18. {
    19. InitializeComponent();
    20. }
    21. Bitmap bmp;
    22. string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
    23. string img = "";
    24. double fontScale = 4D;
    25. int thickness = 4;
    26. LineTypes lineType = LineTypes.Link4;
    27. PaddleConfig paddleConfig;
    28. PaddleDetector d;
    29. String startupPath;
    30. float confidence = 0.90f;
    31. DateTime dt1 = DateTime.Now;
    32. DateTime dt2 = DateTime.Now;
    33. StringBuilder sb = new StringBuilder();
    34. private void Form1_Load(object sender, EventArgs e)
    35. {
    36. startupPath = Application.StartupPath;
    37. paddleConfig = PaddleConfig.FromModelDir(startupPath + "\\model\\");
    38. string configYmlPath = startupPath + "\\model\\infer_cfg.yml";
    39. d = new PaddleDetector(paddleConfig, configYmlPath, PaddleDevice.Mkldnn());
    40. }
    41. private void button1_Click(object sender, EventArgs e)
    42. {
    43. OpenFileDialog ofd = new OpenFileDialog();
    44. ofd.Filter = fileFilter;
    45. if (ofd.ShowDialog() != DialogResult.OK) return;
    46. pictureBox1.Image = null;
    47. img = ofd.FileName;
    48. bmp = new Bitmap(img);
    49. pictureBox1.Image = new Bitmap(img);
    50. textBox1.Text = "";
    51. }
    52. private void button2_Click(object sender, EventArgs e)
    53. {
    54. if (img == "")
    55. {
    56. return;
    57. }
    58. sb.Clear();
    59. Mat src = Cv2.ImRead(img);
    60. dt1 = DateTime.Now;
    61. DetectionResult[] r = d.Run(src);
    62. dt2 = DateTime.Now;
    63. Scalar scalar;
    64. for (int i = 0; i < r.Length; i++)
    65. {
    66. if (r[i].Confidence > confidence)
    67. {
    68. scalar = Scalar.RandomColor();
    69. Cv2.Rectangle(src, r[i].Rect, scalar, 4, LineTypes.Link8, 0);
    70. Cv2.PutText(src, r[i].LabelName + "(" + r[i].Confidence + ")", new OpenCvSharp.Point(r[i].Rect.X + r[i].Rect.Width / 2, r[i].Rect.Y + r[i].Rect.Height / 2), HersheyFonts.HersheyComplex, fontScale, scalar, thickness, lineType, false);
    71. sb.AppendLine(string.Format("{0}({1}) ({2},{3},{4},{5})",
    72. r[i].LabelName
    73. , r[i].Confidence
    74. , r[i].Rect.Left
    75. , r[i].Rect.Top
    76. , r[i].Rect.Right
    77. , r[i].Rect.Bottom
    78. ));
    79. }
    80. }
    81. sb.AppendLine("耗时:" + (dt2 - dt1).TotalMilliseconds + "ms");
    82. textBox1.Text = sb.ToString();
    83. pictureBox2.Image = BitmapConverter.ToBitmap(src);
    84. }
    85. }
    86. }

    下载 

    Demo下载

  • 相关阅读:
    计算机毕业设计ssm计算机学院大学生实践指导系统lk43b系统+程序+源码+lw+远程部署
    【ComfyUI】Pytorch预训练模型(torch.hub)缓存地址修改
    复旦教授报告400多个安卓漏洞,历时16个月谷歌终于修复,此前曾立flag
    1,2-二苯基-1,2-二(4-羧基苯)乙烯 ;CAS: 1609575-40-7
    好物周刊#8:开源镜像站
    无人机遥控中应用的2.4GHz无线芯片
    基于学生成绩管理系统(附源代码及数据库)
    Spring Boot 集成阿里云直播点播
    一起来学Kotlin:概念:17. Kotlin Extension Function / Method (扩展函数)
    Dynamics CRM - 通过 C# Plugin 来 abandon Business Process Flow
  • 原文地址:https://blog.csdn.net/lw112190/article/details/132618023