首页 > 编程语言 >C# OpenVino Yolov8 Seg 分割

C# OpenVino Yolov8 Seg 分割

时间:2023-10-02 12:07:37浏览次数:31  
标签:OpenVino using C# image System Seg result path new


效果

C# OpenVino Yolov8 Seg 分割_人工智能

C# OpenVino Yolov8 Seg 分割_人工智能_02

C# OpenVino Yolov8 Seg 分割_人工智能_03

 

C# OpenVino Yolov8 Seg 分割_YOLO_04

项目

C# OpenVino Yolov8 Seg 分割_System_05

代码

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 OpenCvSharp;

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

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        String startupPath;
        string classer_path;
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
        String model_path;
        Core core;
        Mat image;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            textBox1.Text = "";
            image = new Mat(image_path);
        }

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

            // 配置图片数据
            Mat image = new Mat(image_path);
            int max_image_length = image.Cols > image.Rows ? image.Cols : image.Rows;
            Mat max_image = Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);
            Rect roi = new Rect(0, 0, image.Cols, image.Rows);
            image.CopyTo(new Mat(max_image, roi));

            float[] det_result_array = new float[8400 * 116];
            float[] proto_result_array = new float[32 * 160 * 160];
            float[] factors = new float[4];
            factors[0] = factors[1] = (float)(max_image_length / 640.0);
            factors[2] = image.Rows;
            factors[3] = image.Cols;

            byte[] image_data = max_image.ImEncode(".bmp");
            //存储byte的长度
            ulong image_size = Convert.ToUInt64(image_data.Length);
            // 加载推理图片数据
            core.load_input_data("images", image_data, image_size, 1);

            dt1 = DateTime.Now;
            // 模型推理
            core.infer();
            dt2 = DateTime.Now;

            // 读取推理结果
            det_result_array = core.read_infer_result<float>("output0", 8400 * 116);
            proto_result_array = core.read_infer_result<float>("output1", 32 * 160 * 160);

            SegmentationResult result_pro= new SegmentationResult(classer_path, factors);
            Mat result_image = result_pro.draw_result(result_pro.process_result(det_result_array, proto_result_array), image.Clone());

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            startupPath = System.Windows.Forms.Application.StartupPath;
            model_path = startupPath + "\\yolov8n-seg.onnx";
            core = new Core(model_path, "CPU");
            classer_path = "yolov8-detect-lable.txt";
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            core.delet();
        }
    }
}

完整Demo下载

标签:OpenVino,using,C#,image,System,Seg,result,path,new
From: https://blog.51cto.com/u_2617730/7682506

相关文章

  • C# OpenVinoSharp PP-TinyPose 人体姿态识别
    效果项目部分代码usingOpenCvSharp;usingOpenCvSharp.Extensions;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace......
  • C# OpenVino Yolov8 Detect 目标检测
    效果项目 代码usingOpenCvSharp;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingstaticSystem.Net.Mime.MediaTypeName......
  • 【TypeScript】一直提示 :无法重新声明块范围变量
    【TypeScript】一直提示:无法重新声明块范围变量问题描述:在VSCode中编写ts代码时,编写保存完之后,通过tsc文件名.ts编译就会看到变量名下面出现了红色的波浪线,提示的内容是无法重新声明块范围变量。解决方法:在终端只需要使用tsc--init生成tsconfig.json文件就可以解决了。或者在当......
  • 【C++】函数重载 ③ ( 为函数指针赋值重载函数 )
    文章目录一、函数指针回顾1、函数指针概念2、函数指针语法3、代码示例-函数指针示例二、为函数指针赋值重载函数1、为函数指针赋值重载函数2、代码示例-为函数指针赋值重载函数博客总结:重载函数:使用相同的函数名,定义不同的函数参数列表;判定标准:只有函数......
  • 主流常见关系数据库分页sql语句写法。MySQL、PostgreSQL、SQLite、Oracle、DB2、SQL S
    前言1.分页sql逻辑:每页10条,取第3页。即取第21~30条数据1.1.MySQL/SQLite/PostgreSQLselect*fromdemolimit10offset20;select*fromdemolimit20,10;--PostgreSQL不支持该写法1.2.Oracle12C+Oracle11g之前很难用,Oracle12C+与MySQL用法格式一样了,只是语法关......
  • Gromacs模拟体系构建----进阶版
    Gromacs是目前广泛使用的分子模拟软件,其在生物、材料等领域的模拟表现出较为突出的优势。之前,本公众号介绍过一系列体系的模拟以及gromacs的使用办法和教程。本次,将为大家介绍一种进阶版的模型构建方法。在之前的介绍中,我们了解到可以通过insert-molecules和editconf等命令构建模拟......
  • DC电源模块过压保护功能介绍
    BOSHIDADC电源模块过压保护功能介绍DC电源模块(也叫直流电源模块)是一种常见的设备,它可以将交流电转换为直流电,用于供电给各种电子设备。DC电源模块通常具有多种保护功能,其中过压保护是其中一项重要的保护功能。过压保护是指当DC电源模块输出电压高于预设值时,系统会自动进行保护操作......
  • Final Cut Pro最新中文版下载-FCPX软件下载 安装包下载方式
    FinalCutProX 是mac客户端最专业的视频剪辑软件,拥有最完善的视频处理功能,可以编辑不同分辨率的视频,搭配本站的FCPX插件使用效果更佳。新版的FinalCutProXforMac新增模糊、光晕等360°效果让后期制作的速度得以提升,帮助用户创作出令人赞叹的作品。本站提供 Final......
  • Python爬虫源码,Behance 作品图片及内容 selenium 采集爬虫
    前面有分享过requests采集Behance作品信息的爬虫,这篇带来另一个版本供参考,使用的是无头浏览器selenium采集,主要的不同方式是使用selenium驱动浏览器获取到页面源码,后面获取信息的话与前篇一致。Python爬虫源码,Behance作品图片及内容采集爬虫附工具脚本!理论上,几乎所有的页面内......
  • FCPX最新中文版下载 支持M1/M2 安装包下载方式
    fcpx全称FinalCutProX是一款由Macromedia(现已被Adobe收购)推出,之后由苹果公司接手研发、销售的非线性视频剪辑软件。能在装载英特尔处理器和macOSMojave10.14.6以后版本的Mac电脑上运行。本软件能让用户将视频记录和传输至硬盘上(内置或外接),之后进行编辑、剪辑、处理和输......