当前位置: 首页 > 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系统中…...

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

【Oracle APEX开发小技巧12】

有如下需求&#xff1a; 有一个问题反馈页面&#xff0c;要实现在apex页面展示能直观看到反馈时间超过7天未处理的数据&#xff0c;方便管理员及时处理反馈。 我的方法&#xff1a;直接将逻辑写在SQL中&#xff0c;这样可以直接在页面展示 完整代码&#xff1a; SELECTSF.FE…...

从WWDC看苹果产品发展的规律

WWDC 是苹果公司一年一度面向全球开发者的盛会&#xff0c;其主题演讲展现了苹果在产品设计、技术路线、用户体验和生态系统构建上的核心理念与演进脉络。我们借助 ChatGPT Deep Research 工具&#xff0c;对过去十年 WWDC 主题演讲内容进行了系统化分析&#xff0c;形成了这份…...

8k长序列建模,蛋白质语言模型Prot42仅利用目标蛋白序列即可生成高亲和力结合剂

蛋白质结合剂&#xff08;如抗体、抑制肽&#xff09;在疾病诊断、成像分析及靶向药物递送等关键场景中发挥着不可替代的作用。传统上&#xff0c;高特异性蛋白质结合剂的开发高度依赖噬菌体展示、定向进化等实验技术&#xff0c;但这类方法普遍面临资源消耗巨大、研发周期冗长…...

微信小程序 - 手机震动

一、界面 <button type"primary" bindtap"shortVibrate">短震动</button> <button type"primary" bindtap"longVibrate">长震动</button> 二、js逻辑代码 注&#xff1a;文档 https://developers.weixin.qq…...

Psychopy音频的使用

Psychopy音频的使用 本文主要解决以下问题&#xff1a; 指定音频引擎与设备&#xff1b;播放音频文件 本文所使用的环境&#xff1a; Python3.10 numpy2.2.6 psychopy2025.1.1 psychtoolbox3.0.19.14 一、音频配置 Psychopy文档链接为Sound - for audio playback — Psy…...

c#开发AI模型对话

AI模型 前面已经介绍了一般AI模型本地部署&#xff0c;直接调用现成的模型数据。这里主要讲述讲接口集成到我们自己的程序中使用方式。 微软提供了ML.NET来开发和使用AI模型&#xff0c;但是目前国内可能使用不多&#xff0c;至少实践例子很少看见。开发训练模型就不介绍了&am…...

OpenLayers 分屏对比(地图联动)

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 地图分屏对比在WebGIS开发中是很常见的功能&#xff0c;和卷帘图层不一样的是&#xff0c;分屏对比是在各个地图中添加相同或者不同的图层进行对比查看。…...

AI,如何重构理解、匹配与决策?

AI 时代&#xff0c;我们如何理解消费&#xff1f; 作者&#xff5c;王彬 封面&#xff5c;Unplash 人们通过信息理解世界。 曾几何时&#xff0c;PC 与移动互联网重塑了人们的购物路径&#xff1a;信息变得唾手可得&#xff0c;商品决策变得高度依赖内容。 但 AI 时代的来…...

面向无人机海岸带生态系统监测的语义分割基准数据集

描述&#xff1a;海岸带生态系统的监测是维护生态平衡和可持续发展的重要任务。语义分割技术在遥感影像中的应用为海岸带生态系统的精准监测提供了有效手段。然而&#xff0c;目前该领域仍面临一个挑战&#xff0c;即缺乏公开的专门面向海岸带生态系统的语义分割基准数据集。受…...