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

C# OpenVINO Crack Seg 裂缝分割 裂缝检测

目录

效果

模型信息

项目

代码

数据集

下载


C# OpenVINO Crack Seg 裂缝分割  裂缝检测

效果

模型信息

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

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 + "\\crack_m_best.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 + "\\crack_m_best.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();}}
}

数据集

下载

裂纹数据集带标注信息下载

源码下载

相关文章:

C# OpenVINO Crack Seg 裂缝分割 裂缝检测

目录 效果 模型信息 项目 代码 数据集 下载 C# OpenVINO Crack Seg 裂缝分割 裂缝检测 效果 模型信息 Model Properties ------------------------- date&#xff1a;2024-02-29T16:35:48.364242 author&#xff1a;Ultralytics task&#xff1a;segment version&…...

前后端项目-part03

文章目录 5.4.4 机构名称5.4.4.1 创建实体类Company5.4.4.2 创建实体类CompanyMapper5.4.4.3 创建实体类CompanyService5.4.4.4 创建实体类CompanyController5.4.4.5 后端测试5.4.4.6 修改basic.js5.4.4.7 修改course.vue5.4.4.8 测试5.4.5 课程标签5.4.5.1 效果5.4.5.2 修改co…...

Java 1.8 docker 镜像制作

文章目录 一、下载文件二、精简JRE三、Dockerfile四、构建镜像五、容器测试 一、下载文件 glibc 下载地址 glibc-2.33-r0.apk glibc-bin-2.33-r0.apk glibc-i18n-2.33-r0.apk rsa sgerrand.rsa.pub jre 1.8 jre-8u201-linux-x64.tar.gz 二、精简JRE 解压 tar -zxvf jre-8…...

python中自定义报错

class MyError(Exception):def __init__(self,num):#录入的数Exception.__init__(self)self.numnumdef __str__(self):return 这是我定义的第%d个异常 %(self.num)使用 try:raise MyError(4) except MyError as e:print(e)raise 其作用是指定抛出的异常名称&#xff0c;以及异常…...

part1:sora技术

1.Sora能力边界探索 从sora的视频合集里看到了多段视频&#xff0c;假如我不知道这是sora视频合计&#xff0c;估计我第一反应并不是AI生成了这些视频&#xff0c;可以说在我这里通过了图灵测试&#x1f60a;。 在视频合集里还有同一场景的多角度/镜头的生成能力&#xff0c;让…...

RK3568平台开发系列讲解(基础篇)文件私有数据

🚀返回专栏总目录 文章目录 一、文件私有数据二、文件私有数据实验沉淀、分享、成长,让自己和他人都能有所收获!😄 一、文件私有数据 Linux 中并没有明确规定要使用文件私有数据,但是在 linux 驱动源码中,广泛使用了文件私有数据,这是 Linux 驱动遵循的“潜规则”,实…...

跨时钟信号处理方法

1. 背景 现在的芯片&#xff08;比如SOC&#xff0c;片上系统&#xff09;集成度和复杂度越来越高&#xff0c;通常一颗芯片上会有许多不同的信号工作在不同的时钟频率下。比如SOC芯片中的CPU通常会工作在一个频率上&#xff0c;总线信号&#xff08;比如DRAM BUS&#xff09;会…...

OD(13)之Mermaid饼图和象限图

OD(13)之Mermaid饼图和象限图使用详解 Author: Once Day Date: 2024年2月29日 漫漫长路才刚刚开始… 全系列文章可参考专栏: Mermaid使用指南_Once_day的博客-CSDN博客 参考文章: 关于 Mermaid | Mermaid 中文网 (nodejs.cn)Mermaid | Diagramming and charting tool‍‌⁡…...

基于springboot+vue的智能无人仓库管理系统

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战&#xff0c;欢迎高校老师\讲师\同行交流合作 ​主要内容&#xff1a;毕业设计(Javaweb项目|小程序|Pyt…...

图神经网络实战——图论

图神经网络实战——图论 0. 前言1. 图属性1.1 有向图和无向图1.2 加权图与非加权图1.3 连通图非连通图1.4 其它图类型 2. 图概念2.1 基本对象2.2 图的度量指标2.2 邻接矩阵表示法 3. 图算法3.1 广度优先搜索3.2 深度优先搜索 小结系列链接 0. 前言 图论 (Graph theory) 是数学…...

【PHP进阶】Rabbitmq的实际使用

RabbitMQ是一个流行的消息队列中间件&#xff0c;它提供了可靠的消息传递机制。在使用RabbitMQ时&#xff0c;有几个重要的概念需要了解&#xff1a; 消息队列&#xff08;Message Queue&#xff09;&#xff1a;RabbitMQ中的核心概念之一。它是消息的缓冲区&#xff0c;用于存…...

如何解决机器视觉高速图像处理软件的加密需求?

高速图像处理在机器视觉中的应用重要性 在机器视觉行业中&#xff0c;高速图像处理软件的作用至关重要&#xff0c;它使得机器能够迅速分析和处理成千上万的图像数据。这种能力在制造业、安防系统、交通监控等多个领域发挥着核心作用&#xff0c;如在制造业中&#xff0c;高速…...

Linux的条件变量

条件变量 条件变量本身不是锁&#xff0c;但是它可以造成线程阻塞。通常于互斥锁配合使用。给多线程提供一个会和的场合。 使用互斥量保护共享数据使用条件变量可以造成线程阻塞&#xff0c;等待某个条件的发生&#xff0c;当条件满足的时候解除阻塞。 条件变量的两个动作&a…...

【Python笔记-设计模式】状态模式

一、说明 状态模式是一种行为设计模式&#xff0c;用于解决对象在不同状态下具有不同行为 (一) 解决问题 在对象行为根据对象状态而改变时&#xff0c;规避使用大量的条件语句来判断对象的状态&#xff0c;提高系统可维护性 (二) 使用场景 当对象的行为取决于其状态&#…...

Pytorch 复习总结 5

Pytorch 复习总结&#xff0c;仅供笔者使用&#xff0c;参考教材&#xff1a; 《动手学深度学习》Stanford University: Practical Machine Learning 本文主要内容为&#xff1a;Pytorch 卷积神经网络。 本文先介绍了 Pytorch 语法汇总&#xff1a; Pytorch 张量的常见运算、…...

Codeforces Round 930 (Div. 2)

Codeforces Round 930 (Div. 2) Codeforces Round 930 (Div. 2) A. Shuffle Party 题意&#xff1a; 给出长度为n的整数数组a&#xff0c; a i a_i ai​ i&#xff0c;对于k>2的下标进行运算&#xff0c;设d为k除本身外最大的除数&#xff0c; 操作为交换( a k a_k ak​…...

c语言求平方与倒数序列的部分和

本题要求对两个正整数m和n&#xff08;m≤n&#xff09;编写程序&#xff0c;计算序列和m21/m(m1)21/(m1)⋯n21/n。 输入格式: 输入在一行中给出两个正整数m和n&#xff08;m≤n&#xff09;&#xff0c;其间以空格分开。 输出格式: 在一行中按照“sum S”的格式输出部分和…...

Vue-4

自定义创建项目 目标&#xff1a;基于 VueCli 自定义创建项目架子 大致步骤&#xff1a; 安装脚手架创建项目 vue create 项目名称选择自定义 选择 Manually select features 这一项 step-1:按下空格 : 选择/取消--勾选请选择&#xff1a;Babel、Router、CSS、Linterstep-2…...

【Acwing】差分矩阵

图1&#xff1a;a和b数组映射表 由于a是b的前缀和数组&#xff0c;因此改变b[ x1][ y1]之后&#xff0c;受到影响的a中元素如右半图所示 图2&#xff1a;求b数组的前缀和 #include<bits/stdc.h> using namespace std;int n,m,q; int a[1010][1010]; int b[1010][1010]…...

Linux系统加固:如何有效管理系统账号

Linux系统加固&#xff1a;如何有效管理系统账号 1.1 口令重复次数限制1.2 避免系统存在uid相同的账号1.3 空密码的帐户1.4 口令复杂度1.5 口令生存期1.6 登录失败次数锁定策略 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; 在Linux系统中…...

cf2117E

原题链接&#xff1a;https://codeforces.com/contest/2117/problem/E 题目背景&#xff1a; 给定两个数组a,b&#xff0c;可以执行多次以下操作&#xff1a;选择 i (1 < i < n - 1)&#xff0c;并设置 或&#xff0c;也可以在执行上述操作前执行一次删除任意 和 。求…...

使用van-uploader 的UI组件,结合vue2如何实现图片上传组件的封装

以下是基于 vant-ui&#xff08;适配 Vue2 版本 &#xff09;实现截图中照片上传预览、删除功能&#xff0c;并封装成可复用组件的完整代码&#xff0c;包含样式和逻辑实现&#xff0c;可直接在 Vue2 项目中使用&#xff1a; 1. 封装的图片上传组件 ImageUploader.vue <te…...

第25节 Node.js 断言测试

Node.js的assert模块主要用于编写程序的单元测试时使用&#xff0c;通过断言可以提早发现和排查出错误。 稳定性: 5 - 锁定 这个模块可用于应用的单元测试&#xff0c;通过 require(assert) 可以使用这个模块。 assert.fail(actual, expected, message, operator) 使用参数…...

CMake控制VS2022项目文件分组

我们可以通过 CMake 控制源文件的组织结构,使它们在 VS 解决方案资源管理器中以“组”(Filter)的形式进行分类展示。 🎯 目标 通过 CMake 脚本将 .cpp、.h 等源文件分组显示在 Visual Studio 2022 的解决方案资源管理器中。 ✅ 支持的方法汇总(共4种) 方法描述是否推荐…...

2025季度云服务器排行榜

在全球云服务器市场&#xff0c;各厂商的排名和地位并非一成不变&#xff0c;而是由其独特的优势、战略布局和市场适应性共同决定的。以下是根据2025年市场趋势&#xff0c;对主要云服务器厂商在排行榜中占据重要位置的原因和优势进行深度分析&#xff1a; 一、全球“三巨头”…...

网站指纹识别

网站指纹识别 网站的最基本组成&#xff1a;服务器&#xff08;操作系统&#xff09;、中间件&#xff08;web容器&#xff09;、脚本语言、数据厍 为什么要了解这些&#xff1f;举个例子&#xff1a;发现了一个文件读取漏洞&#xff0c;我们需要读/etc/passwd&#xff0c;如…...

排序算法总结(C++)

目录 一、稳定性二、排序算法选择、冒泡、插入排序归并排序随机快速排序堆排序基数排序计数排序 三、总结 一、稳定性 排序算法的稳定性是指&#xff1a;同样大小的样本 **&#xff08;同样大小的数据&#xff09;**在排序之后不会改变原始的相对次序。 稳定性对基础类型对象…...

【C++特殊工具与技术】优化内存分配(一):C++中的内存分配

目录 一、C 内存的基本概念​ 1.1 内存的物理与逻辑结构​ 1.2 C 程序的内存区域划分​ 二、栈内存分配​ 2.1 栈内存的特点​ 2.2 栈内存分配示例​ 三、堆内存分配​ 3.1 new和delete操作符​ 4.2 内存泄漏与悬空指针问题​ 4.3 new和delete的重载​ 四、智能指针…...

如何更改默认 Crontab 编辑器 ?

在 Linux 领域中&#xff0c;crontab 是您可能经常遇到的一个术语。这个实用程序在类 unix 操作系统上可用&#xff0c;用于调度在预定义时间和间隔自动执行的任务。这对管理员和高级用户非常有益&#xff0c;允许他们自动执行各种系统任务。 编辑 Crontab 文件通常使用文本编…...

C++ 设计模式 《小明的奶茶加料风波》

&#x1f468;‍&#x1f393; 模式名称&#xff1a;装饰器模式&#xff08;Decorator Pattern&#xff09; &#x1f466; 小明最近上线了校园奶茶配送功能&#xff0c;业务火爆&#xff0c;大家都在加料&#xff1a; 有的同学要加波霸 &#x1f7e4;&#xff0c;有的要加椰果…...