C# PaddleDetection 目标检测 ( yolov3_darknet)

这篇具有很好参考价值的文章主要介绍了C# PaddleDetection 目标检测 ( yolov3_darknet)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

效果

项目

代码

infer_cfg.yml label_list中为可识别的目标

下载 


效果

C# PaddleDetection 目标检测 ( yolov3_darknet),AI,C#,OpenCV,C#目标检测

项目

VS2022+.net4.8+OpenCvSharp4+Sdcb.PaddleDetection

C# PaddleDetection 目标检测 ( yolov3_darknet),AI,C#,OpenCV,C#目标检测

代码

using OpenCvSharp;
using OpenCvSharp.Extensions;
using Sdcb.PaddleDetection;
using Sdcb.PaddleInference;
using System;
using System.Drawing;
using System.Windows.Forms;
using YamlDotNet;

namespace PaddleDetection目标检测__yolov3_darknet_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

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

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

        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);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (img == "")
            {
                return;
            }

            Mat src = Cv2.ImRead(img);
            DetectionResult[] r = d.Run(src);

            for (int i = 0; i < r.Length; i++)
            {
                if (r[i].Confidence > confidence)
                {
                    Scalar scalar = Scalar.RandomColor();
                    Cv2.Rectangle(src, r[i].Rect, scalar, 1, LineTypes.Link8, 0);
                    Cv2.PutText(src, r[i].LabelName, 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);
                }
            }

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

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

using OpenCvSharp;
using OpenCvSharp.Extensions;
using Sdcb.PaddleDetection;
using Sdcb.PaddleInference;
using System;
using System.Drawing;
using System.Windows.Forms;
using YamlDotNet;

namespace PaddleDetection目标检测__yolov3_darknet_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

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

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

        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);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (img == "")
            {
                return;
            }

            Mat src = Cv2.ImRead(img);
            DetectionResult[] r = d.Run(src);

            for (int i = 0; i < r.Length; i++)
            {
                if (r[i].Confidence > confidence)
                {
                    Scalar scalar = Scalar.RandomColor();
                    Cv2.Rectangle(src, r[i].Rect, scalar, 1, LineTypes.Link8, 0);
                    Cv2.PutText(src, r[i].LabelName, 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);
                }
            }

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

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

infer_cfg.yml label_list中为可识别的目标

mode: paddle
draw_threshold: 0.5
metric: COCO
use_dynamic_shape: false
arch: YOLO
min_subgraph_size: 3
Preprocess:
- interp: 2
  keep_ratio: false
  target_size:
  - 608
  - 608
  type: Resize
- is_scale: true
  mean:
  - 0.485
  - 0.456
  - 0.406
  std:
  - 0.229
  - 0.224
  - 0.225
  type: NormalizeImage
- type: Permute
label_list:
- person
- bicycle
- car
- motorcycle
- airplane
- bus
- train
- truck
- boat
- traffic light
- fire hydrant
- stop sign
- parking meter
- bench
- bird
- cat
- dog
- horse
- sheep
- cow
- elephant
- bear
- zebra
- giraffe
- backpack
- umbrella
- handbag
- tie
- suitcase
- frisbee
- skis
- snowboard
- sports ball
- kite
- baseball bat
- baseball glove
- skateboard
- surfboard
- tennis racket
- bottle
- wine glass
- cup
- fork
- knife
- spoon
- bowl
- banana
- apple
- sandwich
- orange
- broccoli
- carrot
- hot dog
- pizza
- donut
- cake
- chair
- couch
- potted plant
- bed
- dining table
- toilet
- tv
- laptop
- mouse
- remote
- keyboard
- cell phone
- microwave
- oven
- toaster
- sink
- refrigerator
- book
- clock
- vase
- scissors
- teddy bear
- hair drier
- toothbrush

下载 

Demo下载文章来源地址https://www.toymoban.com/news/detail-610873.html

到了这里,关于C# PaddleDetection 目标检测 ( yolov3_darknet)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包