当前位置: 首页 > news >正文

C# Onnx GroundingDINO 开放世界目标检测

目录

介绍

效果

模型信息

项目

代码

下载


介绍

地址:https://github.com/IDEA-Research/GroundingDINO

Official implementation of the paper "Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection"

效果

在运行程序时,要注意输入的提示词的格式,类别之间以" . "隔开,并且确保类别名称在词典文件 vocab.txt里是存在的,而且输入提示词里的类别名称是你想要检测的目标类别,否则可能会检测不到目标的。 

模型信息

Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:img
tensor:Float[-1, 3, -1, -1]
name:input_ids
tensor:Int64[-1, -1]
name:attention_mask
tensor:Bool[-1, -1]
name:position_ids
tensor:Int64[-1, -1]
name:token_type_ids
tensor:Int64[-1, -1]
name:text_token_mask
tensor:Bool[-1, -1, -1]
---------------------------------------------------------------

Outputs
-------------------------
name:logits
tensor:Float[-1, -1, -1]
name:boxes
tensor:Float[-1, -1, 4]
---------------------------------------------------------------

项目

代码

Form1

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Onnx_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        GroundingDINO groundingDINO = new GroundingDINO("model/groundingdino_swint_ogc.onnx", 0.3f, "model/vocab.txt", 0.25f, true);

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

        StringBuilder sb = new StringBuilder();

        Mat image;
        Mat result_image;

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

            pictureBox1.Image = null;
            pictureBox2.Image = null;
            txtInfo.Text = "";

            image_path = ofd.FileName;
            pictureBox2.Image = new Bitmap(image_path);
            image = new Mat(image_path);

        }

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

            if (String.IsNullOrEmpty(txt_input_text.Text))
            {
                return;
            }

            pictureBox1.Image = null;
            txtInfo.Text = "检测中,请稍等……";
            button3.Enabled = false;
            if (pictureBox1.Image != null)
            {
                pictureBox1.Image.Dispose();
                pictureBox1.Image = null;
            }
            Application.DoEvents();

            String text_prompt = txt_input_text.Text;

            List<Object> objects = groundingDINO.detect(image, text_prompt);

            result_image = image.Clone();
            sb.Clear();
            for (int i = 0; i < objects.Count; i++)
            {
                Cv2.Rectangle(result_image, objects[i].box, new Scalar(0, 0, 255), 2);
                Cv2.PutText(result_image, objects[i].text + " " + objects[i].prob.ToString("F2"), new OpenCvSharp.Point(objects[i].box.X, objects[i].box.Y), HersheyFonts.HersheySimplex, 1, new Scalar(0, 0, 255), 2); ;
                sb.AppendLine(objects[i].text + " " + objects[i].prob.ToString("F2"));
            }
            pictureBox1.Image = new Bitmap(result_image.ToMemoryStream());

            button3.Enabled = true;
            txtInfo.Text = sb.ToString();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            image_path = "test_img/cat_dog.jpeg";
            pictureBox2.Image = new Bitmap(image_path);
            image = new Mat(image_path);
        }
    }
}

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace Onnx_Demo
{public partial class Form1 : Form{public Form1(){InitializeComponent();}GroundingDINO groundingDINO = new GroundingDINO("model/groundingdino_swint_ogc.onnx", 0.3f, "model/vocab.txt", 0.25f, true);string image_path = "";string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";StringBuilder sb = new StringBuilder();Mat image;Mat result_image;private void button2_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;pictureBox2.Image = null;txtInfo.Text = "";image_path = ofd.FileName;pictureBox2.Image = new Bitmap(image_path);image = new Mat(image_path);}private void button3_Click(object sender, EventArgs e){if (image_path == ""){return;}if (String.IsNullOrEmpty(txt_input_text.Text)){return;}pictureBox1.Image = null;txtInfo.Text = "检测中,请稍等……";button3.Enabled = false;if (pictureBox1.Image != null){pictureBox1.Image.Dispose();pictureBox1.Image = null;}Application.DoEvents();String text_prompt = txt_input_text.Text;List<Object> objects = groundingDINO.detect(image, text_prompt);result_image = image.Clone();sb.Clear();for (int i = 0; i < objects.Count; i++){Cv2.Rectangle(result_image, objects[i].box, new Scalar(0, 0, 255), 2);Cv2.PutText(result_image, objects[i].text + " " + objects[i].prob.ToString("F2"), new OpenCvSharp.Point(objects[i].box.X, objects[i].box.Y), HersheyFonts.HersheySimplex, 1, new Scalar(0, 0, 255), 2); ;sb.AppendLine(objects[i].text + " " + objects[i].prob.ToString("F2"));}pictureBox1.Image = new Bitmap(result_image.ToMemoryStream());button3.Enabled = true;txtInfo.Text = sb.ToString();}private void Form1_Load(object sender, EventArgs e){image_path = "test_img/cat_dog.jpeg";pictureBox2.Image = new Bitmap(image_path);image = new Mat(image_path);}}
}

下载

源码下载

http://www.lryc.cn/news/292950.html

相关文章:

  • PyCharm / DataSpell 导入WSL2 解析器,实现GPU加速
  • Android矩阵Matrix裁切setRectToRect拉伸Bitmap替代Bitmap.createScaledBitmap缩放,Kotlin
  • TensorFlow2实战-系列教程11:RNN文本分类3
  • 故障诊断 | 一文解决,RF随机森林的故障诊断(Matlab)
  • DAO设计模式
  • 【Midjourney】新手指南:参数设置
  • 阿里云a10GPU,centos7,cuda11.2环境配置
  • RTSP/Onvif协议视频平台EasyNVR激活码授权异常该如何解决
  • React16源码: React中event事件对象的创建过程源码实现
  • 深度学习(12)--Mnist分类任务
  • AI工具【OCR 01】Java可使用的OCR工具Tess4J使用举例(身份证信息识别核心代码及信息提取方法分享)
  • 【MySQL复制】半同步复制
  • PHP面试知识点--echo、print、print_r、var_dump区别
  • centos 7 部署若依前后端分离项目
  • RFID手持终端_智能pda手持终端设备定制方案
  • 51单片机学习——矩阵按键
  • 重写Sylar基于协程的服务器(1、日志模块的架构)
  • ElementUI Form:Radio 单选框
  • react-activation实现缓存,且部分页面刷新缓存,清除缓存
  • idea 中 tomcat 乱码问题修复
  • Modbus协议学习第七篇之libmodbus库API介绍(modbus_write_bits等)
  • 第九节HarmonyOS 常用基础组件13-TimePicker
  • 力扣刷题-55.跳跃游戏
  • Ruby安装演示教程
  • 前端使用vue-simple-uploader进行分片上传
  • Java 源代码中常见的数据类型
  • Web3行业研究逐步加强,“链上数据”缘何成为关注焦点?
  • 逸学区块链【solidity】真随机数
  • 【WPF.NET开发】优化性能:对象行为
  • uniapp中封装一个svg转base64的组件