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:2024-02-29T16:35:48.364242 author:Ultralytics task: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 其作用是指定抛出的异常名称,以及异常…...
part1:sora技术
1.Sora能力边界探索 从sora的视频合集里看到了多段视频,假如我不知道这是sora视频合计,估计我第一反应并不是AI生成了这些视频,可以说在我这里通过了图灵测试😊。 在视频合集里还有同一场景的多角度/镜头的生成能力,让…...
RK3568平台开发系列讲解(基础篇)文件私有数据
🚀返回专栏总目录 文章目录 一、文件私有数据二、文件私有数据实验沉淀、分享、成长,让自己和他人都能有所收获!😄 一、文件私有数据 Linux 中并没有明确规定要使用文件私有数据,但是在 linux 驱动源码中,广泛使用了文件私有数据,这是 Linux 驱动遵循的“潜规则”,实…...
跨时钟信号处理方法
1. 背景 现在的芯片(比如SOC,片上系统)集成度和复杂度越来越高,通常一颗芯片上会有许多不同的信号工作在不同的时钟频率下。比如SOC芯片中的CPU通常会工作在一个频率上,总线信号(比如DRAM BUS)会…...
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的智能无人仓库管理系统
博主主页:猫头鹰源码 博主简介:Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战,欢迎高校老师\讲师\同行交流合作 主要内容:毕业设计(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是一个流行的消息队列中间件,它提供了可靠的消息传递机制。在使用RabbitMQ时,有几个重要的概念需要了解: 消息队列(Message Queue):RabbitMQ中的核心概念之一。它是消息的缓冲区,用于存…...
如何解决机器视觉高速图像处理软件的加密需求?
高速图像处理在机器视觉中的应用重要性 在机器视觉行业中,高速图像处理软件的作用至关重要,它使得机器能够迅速分析和处理成千上万的图像数据。这种能力在制造业、安防系统、交通监控等多个领域发挥着核心作用,如在制造业中,高速…...
Linux的条件变量
条件变量 条件变量本身不是锁,但是它可以造成线程阻塞。通常于互斥锁配合使用。给多线程提供一个会和的场合。 使用互斥量保护共享数据使用条件变量可以造成线程阻塞,等待某个条件的发生,当条件满足的时候解除阻塞。 条件变量的两个动作&a…...
【Python笔记-设计模式】状态模式
一、说明 状态模式是一种行为设计模式,用于解决对象在不同状态下具有不同行为 (一) 解决问题 在对象行为根据对象状态而改变时,规避使用大量的条件语句来判断对象的状态,提高系统可维护性 (二) 使用场景 当对象的行为取决于其状态&#…...
Pytorch 复习总结 5
Pytorch 复习总结,仅供笔者使用,参考教材: 《动手学深度学习》Stanford University: Practical Machine Learning 本文主要内容为:Pytorch 卷积神经网络。 本文先介绍了 Pytorch 语法汇总: Pytorch 张量的常见运算、…...
Codeforces Round 930 (Div. 2)
Codeforces Round 930 (Div. 2) Codeforces Round 930 (Div. 2) A. Shuffle Party 题意: 给出长度为n的整数数组a, a i a_i ai i,对于k>2的下标进行运算,设d为k除本身外最大的除数, 操作为交换( a k a_k ak…...
c语言求平方与倒数序列的部分和
本题要求对两个正整数m和n(m≤n)编写程序,计算序列和m21/m(m1)21/(m1)⋯n21/n。 输入格式: 输入在一行中给出两个正整数m和n(m≤n),其间以空格分开。 输出格式: 在一行中按照“sum S”的格式输出部分和…...
Vue-4
自定义创建项目 目标:基于 VueCli 自定义创建项目架子 大致步骤: 安装脚手架创建项目 vue create 项目名称选择自定义 选择 Manually select features 这一项 step-1:按下空格 : 选择/取消--勾选请选择:Babel、Router、CSS、Linterstep-2…...
【Acwing】差分矩阵
图1:a和b数组映射表 由于a是b的前缀和数组,因此改变b[ x1][ y1]之后,受到影响的a中元素如右半图所示 图2:求b数组的前缀和 #include<bits/stdc.h> using namespace std;int n,m,q; int a[1010][1010]; int b[1010][1010]…...
Linux系统加固:如何有效管理系统账号
Linux系统加固:如何有效管理系统账号 1.1 口令重复次数限制1.2 避免系统存在uid相同的账号1.3 空密码的帐户1.4 口令复杂度1.5 口令生存期1.6 登录失败次数锁定策略 💖The Begin💖点点关注,收藏不迷路💖 在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_) {} }; // 最小二乘法求圆心和半径 …...
深度学习在微纳光子学中的应用
深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向: 逆向设计 通过神经网络快速预测微纳结构的光学响应,替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…...
云计算——弹性云计算器(ECS)
弹性云服务器:ECS 概述 云计算重构了ICT系统,云计算平台厂商推出使得厂家能够主要关注应用管理而非平台管理的云平台,包含如下主要概念。 ECS(Elastic Cloud Server):即弹性云服务器,是云计算…...
macOS多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用
文章目录 问题现象问题原因解决办法 问题现象 macOS启动台(Launchpad)多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用。 问题原因 很明显,都是Google家的办公全家桶。这些应用并不是通过独立安装的…...
CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云
目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...
汇编常见指令
汇编常见指令 一、数据传送指令 指令功能示例说明MOV数据传送MOV EAX, 10将立即数 10 送入 EAXMOV [EBX], EAX将 EAX 值存入 EBX 指向的内存LEA加载有效地址LEA EAX, [EBX4]将 EBX4 的地址存入 EAX(不访问内存)XCHG交换数据XCHG EAX, EBX交换 EAX 和 EB…...
selenium学习实战【Python爬虫】
selenium学习实战【Python爬虫】 文章目录 selenium学习实战【Python爬虫】一、声明二、学习目标三、安装依赖3.1 安装selenium库3.2 安装浏览器驱动3.2.1 查看Edge版本3.2.2 驱动安装 四、代码讲解4.1 配置浏览器4.2 加载更多4.3 寻找内容4.4 完整代码 五、报告文件爬取5.1 提…...
python执行测试用例,allure报乱码且未成功生成报告
allure执行测试用例时显示乱码:‘allure’ �����ڲ����ⲿ���Ҳ���ǿ�&am…...
Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信
文章目录 Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信前言一、网络通信基础概念二、服务端与客户端的完整流程图解三、每一步的详细讲解和代码示例1. 创建Socket(服务端和客户端都要)2. 绑定本地地址和端口&#x…...
MySQL的pymysql操作
本章是MySQL的最后一章,MySQL到此完结,下一站Hadoop!!! 这章很简单,完整代码在最后,详细讲解之前python课程里面也有,感兴趣的可以往前找一下 一、查询操作 我们需要打开pycharm …...
