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.mzph.cn/news/709377.shtml

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

相关文章

【GitHub】修改默认分支

GitHub的默认分支为main&#xff0c;但我们常常习惯使用master作为默认分支&#xff0c;那在GitHub上如何将master修改为默认分支呢&#xff1f; 全局修改 点击头像&#xff0c;选择菜单栏中的设置 输入master作为默认分支&#xff0c;然后执行updating即可&#xff01; 单项…

智能指针知识点归纳

3.3 智能指针 3.3.1 RAII 和 智能指针实现 智能指针使用RAII 技术将普通的指针封装为一个栈对象&#xff0c;当栈对象的生存周期结束后&#xff0c;会在析构函数中释放掉申请的内存&#xff0c;从而防止内存泄漏。 智能指针的实现&#xff1a; template <typename T>…

springboot+vue实现oss文件存储

前提oss准备工作 进入阿里云官网&#xff1a;阿里云oss官网 注册 搜OSS&#xff0c;点击“对象存储OSS” 第一次进入需要开通&#xff0c;直接点击立即开通&#xff0c;到右上角AccessKey管理中创建AccessKey&#xff0c;并且记住自己的accessKeyId和accessKeySecret&#…

【Unity】构建简单实用的年份选择器(简单原理示范)

在许多应用程序和游戏中&#xff0c;年份选择是一个常见的需求。无论是在日历应用程序中查看事件&#xff0c;还是在历史类游戏中选择时间段&#xff0c;年份选择器都是用户体验的重要组成部分&#xff0c;下面实现一个简易的年份选择器。 一、效果预览&#xff1a; 目录 一、…

python读写查询mysql数据库

我的免费云服务器&#xff0c;阿贝云数据库操作方法 一、pymysql简介pymysql是一个纯Python编写的MySQL客户端库&#xff0c;用于连接和操作MySQL数据库。它实现了Python DB API v2.0规范&#xff0c;提供了与MySQL服务器进行通信所需的所有基本功能。通过pymysql&#xff0c;开…

多模态3D目标检测-自动驾驶

【ECCV2022】|动态快读的多模态3D目标检测框架 | AutoAlignV2: Deformable Feature Aggregation for Dynamic Multi-Modal 3D Object Detection|论文链接|代码链接 【ECCV2022】|同质多模态数据融合和交互用于3D目标检测 | Homogeneous Multi-modal Feature Fusion and Interac…

树莓派驱动编译

驱动编译前提&#xff1a;驱动代码的编译需要提前编译号的内核 驱动&#xff08;3种实现方法&#xff0c;2条路线&#xff09;_驱动编写三种方法-CSDN博客 驱动的编写_驱动编写-CSDN博客 一、概念 1.1、驱动认识 1、裸机程序中是直接操控硬件的&#xff0c;操作系统…

力扣-跳跃游戏

问题 给你一个非负整数数组 nums &#xff0c;你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个下标&#xff0c;如果可以&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 解答 class Solu…

MySQL数据库基础知识总结(适合小白入门使用)一

文章目录 一 数据库数据表的创建等基本操作二 数据类型的测试三 完整性约束条件四 数据表结构的相关操作五 对表中数据的操作六 表达式与查询七 高级的查询功能 一 数据库数据表的创建等基本操作 #注释内容&#xff08;与python很像&#xff09; -- 也为注释内容 -- 创建一个数…

vue3中watch和watchEffect的区别!!!

vue3中watch和watchEffect的区别&#xff01;&#xff01;&#xff01; 在 Vue 3 中&#xff0c;watch 和 watchEffect 都是监听器&#xff0c;但在写法和使用上有所区别。让我们来详细了解一下它们之间的不同&#xff1a; watch: watch 具有一定的惰性&#xff08;lazy&#…

C++ 入门(八)— 常量和字符串

常量和字符串 常量变量常量表达式编译时优化 Constexpr 变量std::string字符串输出 std::coutstd::string可以处理不同长度的字符串字符串输入 std::cin用于输入文本std::getline()不要按值传递Constexpr 字符串 std::string_view可以使用许多不同类型的字符串进行初始化可以接…

v69.字符

1.字符类型 1.1 可以将char类型的变量赋值为整数&#xff0c;也可以赋值为字符! 注意字符要用单引号 ’ ’ 而不是双引号 每一个字符在计算机内部都有一个值去表达它。字符’1’ 在计算机里表示的十进制的整数值为49&#xff0c;就像’A’表示十进制值65。 1.2 scanf 与 p…

C++面试宝典第33题:数组组成最大数

题目 给定一组非负整数nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。 示例1: 输入:nums = [10, 2] 输出:"210" 示例2: 输入:nums = [3, 30, 34, 5, 9] 输出:"…

Flink:流上的“不确定性”(Non-Determinism)

1. 什么是“确定性” 先明确一下什么叫“确定性”&#xff1a;对于一个“操作”来说&#xff0c;如果每次给它的“输入”不变&#xff0c;操作输出的“结果”也不变&#xff0c;那么这个操作就是“确定性“的。通常&#xff0c;我们认为批处理的操作都是确定的&#xff0c;比如…

【查漏补缺你的Vue基础】Vue数据监听深度解析

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

【rust】10 project、crate、mod、pub、use、项目目录层级组织、概念和实战

文章目录 一、项目目录层级组织概念1.1 cargo new 创建同名 的 Project 和 crate1.2 多 crate 的 package1.3 mod 模块1.3.1 创建嵌套 mod1.3.2 mod 树1.3.3 用路径引用 mod1.3.3.1 使用绝对还是相对? 1.3.4 代码可见性1.3.4.1 pub 关键字1.3.4.2 用 super 引用 mod1.3.4.3 用…

阿里Java开发手册(黄山版) LeetCode刷题手册 免费下载

目录 一、阿里Java开发手册(黄山版) 二、LeetCode刷题手册 三、获取方式 今天给大家推荐两个程序员的辅助利器&#xff01;都是平时开发&#xff0c;刷算法能经常用到的书籍&#xff0c;怕百度云分享会失效&#xff0c;获取方式在最下面&#xff0c;永久有效。 一、阿里Jav…

C++ 反向迭代器的设计与实现

在本文开始之前&#xff0c;先明晰几个 关键词 的含义&#xff08;T : 模板参数&#xff09;&#xff1a; Ref : T& / const T&Ptr : T* / const T* 一、反向迭代器设计的上帝视角 我们希望将 反向迭代器 设计成一种适配器——传 list::iterator 得到 list 的反向迭代…

嵌入式学习day28 Linux

1.进程间的通信: 1.管道 2.信号 3.消息队列 4.共享内存 5.信号灯 6.套接字 1.管道: 1.无名管道 无名管道只能用于具有亲缘关系的进程间通信 pipe int pipe(int pipefd[2]); 功能: 创建一个无名管道 …

Lastools工具使用

Lastools工具使用 1、介绍 官网链接 常用的功能 las2las可以进行点云拼接las2txt可以将点云中的有效信息转换为txt文档&#xff08;如xyz坐标&#xff09;lasmerge可以将多个LAS/LAZ文件合并为一个文件Laszip将LAS文件高速压缩到LAZ而不会丢失信息las2text将LAS/LAZ转换为可…