C# OpenVINO Nail Seg 指甲分割 指甲检测

目录

效果

模型信息

项目

代码

数据集

下载


C# OpenVINO Nail Seg 指甲分割  指甲检测

效果

模型信息

Model Properties
-------------------------
date:2024-02-29T16:41:28.273760
author:Ultralytics
task:segment
version:8.1.18
stride:32
batch:1
imgsz:[640, 640]
names:{0: 'Nail'}
---------------------------------------------------------------

Inputs
-------------------------
name:images
tensor:Float[1, 3, 640, 640]
---------------------------------------------------------------

Outputs
-------------------------
name:output0
tensor:Float[1, 37, 8400]
name:output1
tensor:Float[1, 32, 160, 160]
---------------------------------------------------------------

项目

代码

using OpenCvSharp;
using Sdcb.OpenVINO;
using Sdcb.OpenVINO.Natives;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

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

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

        Mat src;

        SegmentationResult result_pro;
        Mat result_image;
        Result seg_result;

        StringBuilder sb = new StringBuilder();

        float[] det_result_array = new float[8400 * 37];
        float[] proto_result_array = new float[32 * 160 * 160];

        // 识别结果类型
        public string[] class_names;

        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 = "";
            src = new Mat(image_path);
            pictureBox2.Image = null;
        }

        unsafe private void button2_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null)
            {
                return;
            }

            pictureBox2.Image = null;
            textBox1.Text = "";
            sb.Clear();

            src = new Mat(image_path);

            Model rawModel = OVCore.Shared.ReadModel(model_path);
            PrePostProcessor pp = rawModel.CreatePrePostProcessor();
            PreProcessInputInfo inputInfo = pp.Inputs.Primary;

            inputInfo.TensorInfo.Layout = Sdcb.OpenVINO.Layout.NHWC;
            inputInfo.ModelInfo.Layout = Sdcb.OpenVINO.Layout.NCHW;

            Model m = pp.BuildModel();
            CompiledModel cm = OVCore.Shared.CompileModel(m, "CPU");
            InferRequest ir = cm.CreateInferRequest();

            Shape inputShape = m.Inputs[0].Shape;

            float[] factors = new float[4];
            factors[0] = 1f * src.Width / inputShape[2];
            factors[1] = 1f * src.Height / inputShape[1];
            factors[2] = src.Rows;
            factors[3] = src.Cols;

            result_pro = new SegmentationResult(class_names, factors,0.3f,0.5f);

            Stopwatch stopwatch = new Stopwatch();
            Mat resized = src.Resize(new OpenCvSharp.Size(inputShape[2], inputShape[1]));
            Mat f32 = new Mat();
            resized.ConvertTo(f32, MatType.CV_32FC3, 1.0 / 255);

            using (Tensor input = Tensor.FromRaw(
                 new ReadOnlySpan<byte>((void*)f32.Data, (int)((long)f32.DataEnd - (long)f32.DataStart)),
                new Shape(1, f32.Rows, f32.Cols, 3),
                ov_element_type_e.F32))
            {
                ir.Inputs.Primary = input;
            }
            double preprocessTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Restart();

            ir.Run();
            double inferTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Restart();

            using (Tensor output_det = ir.Outputs[0])
            using (Tensor output_proto = ir.Outputs[1])
            {
                det_result_array = output_det.GetData<float>().ToArray();
                proto_result_array = output_proto.GetData<float>().ToArray();

                seg_result = result_pro.process_result(det_result_array, proto_result_array);

                double postprocessTime = stopwatch.Elapsed.TotalMilliseconds;
                stopwatch.Stop();

                double totalTime = preprocessTime + inferTime + postprocessTime;

                result_image = src.Clone();
                Mat masked_img = new Mat();

                // 将识别结果绘制到图片上
                for (int i = 0; i < seg_result.length; i++)
                {
                    Cv2.Rectangle(result_image, seg_result.rects[i], new Scalar(0, 0, 255), 2, LineTypes.Link8);
                    Cv2.Rectangle(result_image, new OpenCvSharp.Point(seg_result.rects[i].TopLeft.X, seg_result.rects[i].TopLeft.Y - 20),
                        new OpenCvSharp.Point(seg_result.rects[i].BottomRight.X, seg_result.rects[i].TopLeft.Y), new Scalar(0, 255, 255), -1);
                    Cv2.PutText(result_image, seg_result.classes[i] + "-" + seg_result.scores[i].ToString("0.00"),
                        new OpenCvSharp.Point(seg_result.rects[i].X, seg_result.rects[i].Y - 5),
                        HersheyFonts.HersheySimplex, 0.6, new Scalar(0, 0, 0), 1);
                    Cv2.AddWeighted(result_image, 0.5, seg_result.masks[i], 0.5, 0, masked_img);

                    sb.AppendLine($"{seg_result.classes[i]}:{seg_result.scores[i]:P0}");
                }

                if (seg_result.length > 0)
                {
                    if (pictureBox2.Image != null)
                    {
                        pictureBox2.Image.Dispose();
                    }
                    pictureBox2.Image = new Bitmap(masked_img.ToMemoryStream());
                    sb.AppendLine($"Preprocess: {preprocessTime:F2}ms");
                    sb.AppendLine($"Infer: {inferTime:F2}ms");
                    sb.AppendLine($"Postprocess: {postprocessTime:F2}ms");
                    sb.AppendLine($"Total: {totalTime:F2}ms");
                    textBox1.Text = sb.ToString();
                }
                else
                {
                    textBox1.Text = "无信息";
                }

                masked_img.Dispose();
                result_image.Dispose();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            image_path = "1.jpg";
            pictureBox1.Image = new Bitmap(image_path);

            startupPath = Application.StartupPath;

            model_path = startupPath + "\\nails_seg_s_yolov8.onnx";
            classer_path = startupPath + "\\lable.txt";

            List<string> str = new List<string>();
            StreamReader sr = new StreamReader(classer_path);
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                str.Add(line);
            }
            class_names = str.ToArray();

        }
    }
}

using OpenCvSharp;
using Sdcb.OpenVINO;
using Sdcb.OpenVINO.Natives;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;namespace OpenVINO_Seg
{public partial class Form1 : Form{public Form1(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";string startupPath;string model_path;string classer_path;Mat src;SegmentationResult result_pro;Mat result_image;Result seg_result;StringBuilder sb = new StringBuilder();float[] det_result_array = new float[8400 * 37];float[] proto_result_array = new float[32 * 160 * 160];// 识别结果类型public string[] class_names;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 = "";src = new Mat(image_path);pictureBox2.Image = null;}unsafe private void button2_Click(object sender, EventArgs e){if (pictureBox1.Image == null){return;}pictureBox2.Image = null;textBox1.Text = "";sb.Clear();src = new Mat(image_path);Model rawModel = OVCore.Shared.ReadModel(model_path);PrePostProcessor pp = rawModel.CreatePrePostProcessor();PreProcessInputInfo inputInfo = pp.Inputs.Primary;inputInfo.TensorInfo.Layout = Sdcb.OpenVINO.Layout.NHWC;inputInfo.ModelInfo.Layout = Sdcb.OpenVINO.Layout.NCHW;Model m = pp.BuildModel();CompiledModel cm = OVCore.Shared.CompileModel(m, "CPU");InferRequest ir = cm.CreateInferRequest();Shape inputShape = m.Inputs[0].Shape;float[] factors = new float[4];factors[0] = 1f * src.Width / inputShape[2];factors[1] = 1f * src.Height / inputShape[1];factors[2] = src.Rows;factors[3] = src.Cols;result_pro = new SegmentationResult(class_names, factors,0.3f,0.5f);Stopwatch stopwatch = new Stopwatch();Mat resized = src.Resize(new OpenCvSharp.Size(inputShape[2], inputShape[1]));Mat f32 = new Mat();resized.ConvertTo(f32, MatType.CV_32FC3, 1.0 / 255);using (Tensor input = Tensor.FromRaw(new ReadOnlySpan<byte>((void*)f32.Data, (int)((long)f32.DataEnd - (long)f32.DataStart)),new Shape(1, f32.Rows, f32.Cols, 3),ov_element_type_e.F32)){ir.Inputs.Primary = input;}double preprocessTime = stopwatch.Elapsed.TotalMilliseconds;stopwatch.Restart();ir.Run();double inferTime = stopwatch.Elapsed.TotalMilliseconds;stopwatch.Restart();using (Tensor output_det = ir.Outputs[0])using (Tensor output_proto = ir.Outputs[1]){det_result_array = output_det.GetData<float>().ToArray();proto_result_array = output_proto.GetData<float>().ToArray();seg_result = result_pro.process_result(det_result_array, proto_result_array);double postprocessTime = stopwatch.Elapsed.TotalMilliseconds;stopwatch.Stop();double totalTime = preprocessTime + inferTime + postprocessTime;result_image = src.Clone();Mat masked_img = new Mat();// 将识别结果绘制到图片上for (int i = 0; i < seg_result.length; i++){Cv2.Rectangle(result_image, seg_result.rects[i], new Scalar(0, 0, 255), 2, LineTypes.Link8);Cv2.Rectangle(result_image, new OpenCvSharp.Point(seg_result.rects[i].TopLeft.X, seg_result.rects[i].TopLeft.Y - 20),new OpenCvSharp.Point(seg_result.rects[i].BottomRight.X, seg_result.rects[i].TopLeft.Y), new Scalar(0, 255, 255), -1);Cv2.PutText(result_image, seg_result.classes[i] + "-" + seg_result.scores[i].ToString("0.00"),new OpenCvSharp.Point(seg_result.rects[i].X, seg_result.rects[i].Y - 5),HersheyFonts.HersheySimplex, 0.6, new Scalar(0, 0, 0), 1);Cv2.AddWeighted(result_image, 0.5, seg_result.masks[i], 0.5, 0, masked_img);sb.AppendLine($"{seg_result.classes[i]}:{seg_result.scores[i]:P0}");}if (seg_result.length > 0){if (pictureBox2.Image != null){pictureBox2.Image.Dispose();}pictureBox2.Image = new Bitmap(masked_img.ToMemoryStream());sb.AppendLine($"Preprocess: {preprocessTime:F2}ms");sb.AppendLine($"Infer: {inferTime:F2}ms");sb.AppendLine($"Postprocess: {postprocessTime:F2}ms");sb.AppendLine($"Total: {totalTime:F2}ms");textBox1.Text = sb.ToString();}else{textBox1.Text = "无信息";}masked_img.Dispose();result_image.Dispose();}}private void Form1_Load(object sender, EventArgs e){image_path = "1.jpg";pictureBox1.Image = new Bitmap(image_path);startupPath = Application.StartupPath;model_path = startupPath + "\\nails_seg_s_yolov8.onnx";classer_path = startupPath + "\\lable.txt";List<string> str = new List<string>();StreamReader sr = new StreamReader(classer_path);string line;while ((line = sr.ReadLine()) != null){str.Add(line);}class_names = str.ToArray();}}
}

数据集

下载

指甲数据集带标注信息下载

源码下载

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/499235.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

VirtualBox虚拟机安装 Linux 系统

要想学习各种计算机技术&#xff0c;自然离不开Linux系统。并且目前大多数生产系统都是安装在Linux系统上。常用的Linux系统有 Redhat&#xff0c;Centos&#xff0c;OracleLinux 三种。 三者的区别简单说明如下&#xff1a; Red Hat Enterprise Linux (RHEL): RHEL 是由美国…

InnoDB锁介绍

本文主要介绍MySQL InnoDB引擎中的各种锁策略和锁类别&#xff0c;并针对记录锁做演示以便于理解。 以下内容适用于MySQL 8.0版本。 读写锁 处理并发读/写访问的系统通常实现一个由两种锁类型组成的锁系统。这两种锁通常被称为共享锁(shared lock)和排他锁(exclusive lock)&…

如何在Window系统部署BUG管理软件并结合内网穿透实现远程管理本地BUG

文章目录 前言1. 本地安装配置BUG管理系统2. 内网穿透2.1 安装cpolar内网穿透2.2 创建隧道映射本地服务3. 测试公网远程访问4. 配置固定二级子域名4.1 保留一个二级子域名5.1 配置二级子域名6. 使用固定二级子域名远程 前言 BUG管理软件,作为软件测试工程师的必备工具之一。在…

【数据分享】2001-2022年我国省市县镇四级的逐日平均降水量数据(免费获取\excel\shp格式)

降水数据是我们在各项研究中最常用的气象指标之一&#xff01;之前我们给大家分享过来源于国家青藏高原科学数据中心发布的1961—2022年全国范围的逐日降水栅格数据&#xff08;可查看之前的文章获悉详情&#xff09;&#xff01; 本次我们分享的是2001-2002年我国省市县镇四个…

Linux零基础快速入门

Linux的诞生 Linux创始人:林纳斯 托瓦兹 Linux 诞生于1991年&#xff0c;作者上大学期间 因为创始人在上大学期间经常需要浏览新闻和处理邮件&#xff0c;发现现有的操作系统不好用,于是他决心自己写一个保护模式下的操作系统&#xff0c;这就是Linux的原型&#xff0c;当时他…

方格分割644--2017蓝桥杯

1.用dfs解决&#xff0c;首先这题的方格图形就很像一个走迷宫的类型&#xff0c;迷宫想到dfs&#xff0c;最中心点视为起点&#xff0c;起点有两个小人在这个方格里面对称行动&#xff0c;直到走出迷宫&#xff08;一个人走出来了另一个人就也走出来了&#xff0c;而走过的点会…

【力扣白嫖日记】550.游戏玩法分析IV

前言 练习sql语句&#xff0c;所有题目来自于力扣&#xff08;https://leetcode.cn/problemset/database/&#xff09;的免费数据库练习题。 今日题目&#xff1a; 550.游戏玩法分析IV 表&#xff1a;Activity 列名类型player_idintdevice_idintevent_datedategames_played…

Python 从文件中读取JSON 数据并解析转存

文章目录 文章开篇Json简介Json数据类型Json硬性规则Json数据转化网站Json和Dict类型转换json模块的使用Python数据和Json数据的类型映射json.dumps1.字典数据中含有**存在中文**2.json数据通过缩进符**美观输出**3.对Python数据类型中键进行**排序输出**4.json数据**分隔符的控…

Python调用ChatGPT API使用国内中转key 修改接口教程

大家好&#xff0c;我是淘小白~ 有的客户使用4.0的apikey ,直接使用官方直连的apikey消费很高&#xff0c;有一位客户一个月要消费2万&#xff0c;想使用4.0中转的apikey&#xff0c;使用中转的apikey 需要修改官方的openai库&#xff0c;下面具体说下。 1、首先确保安装的op…

代码随想录算法训练营第二十一天|530.二叉搜索树的最小绝对差、 501.二叉搜索树中的众数 、236. 二叉树的最近公共祖先

530.二叉搜索树的最小绝对差 题目链接/文章讲解&#xff1a; 代码随想录 视频讲解&#xff1a;二叉搜索树中&#xff0c;需要掌握如何双指针遍历&#xff01;| LeetCode&#xff1a;530.二叉搜索树的最小绝对差_哔哩哔哩_bilibili 1.方法1 1.1分析及思路 了解到差值最小的数…

上门服务系统|上门服务小程序|上门服务软件开发

随着移动互联网技术的普及&#xff0c;上门服务小程序系统成为现代企业数字化转型的关键一环。这一系统为消费者提供了更加便捷、高效以及个性化的服务体验&#xff0c;同时也为企业带来了更广阔的商业机会。让我们来看看上门服务小程序系统的优势和功能。 首先&#xff0c;上门…

qt5与qt6的cmake区别

文章目录 使用cmake构建qt项目&#xff0c;坑很多。一是本身就麻烦&#xff0c;二是&#xff0c;确实坑&#xff0c;因为不同的qtcreator版本&#xff0c;选了不同的kits&#xff08;套件&#xff09; 生成的CMakeList.txt文件也不一样。 如果可以的话都选择Qt6的相关选项&…