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();}}
}

數據集

下載

裂紋數據集帶標注信息下載

源碼下載

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/711299.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/711299.shtml
英文地址,請注明出處:http://en.pswp.cn/news/711299.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

去掉WordPress網頁圖片默認鏈接功能

既然是wordpress自動添加的&#xff0c;那么我們在上傳圖片到wordpress后臺多媒體的時候&#xff0c;就可以手動改變鏈接指向或者刪除掉&#xff0c;問題是每次都要這么做很麻煩&#xff0c;更別說有忘記的時候。一次性解決這個問題有兩種方法&#xff0c;一種是No Image Link插…

【生成式AI】ChatGPT原理解析(1/3)- 對ChatGPT的常見誤解

Hung-yi Lee 課件整理 文章目錄 誤解1誤解2ChatGPT真正在做的事情-文字接龍 ChatGPT是在2022年12月7日上線的。 當時試用的感覺十分震撼。 誤解1 我們想讓chatGPT講個笑話&#xff0c;可能會以為它是在一個笑話的集合里面隨機地找一個笑話出來。 我們做一個測試就知道不是這樣…

C# Post數據或文件到指定的服務器進行接收

目錄 應用場景 實現原理 實現代碼 PostAnyWhere類 ashx文件部署 小結 應用場景 不同的接口服務器處理不同的應用&#xff0c;我們會在實際應用中將A服務器的數據提交給B服務器進行數據接收并處理業務。 比如我們想要處理一個OFFICE文件&#xff0c;由用戶上傳到A服務器…

中國汽車電子行業發展現狀分析及投資前景預測報告

全版價格&#xff1a;壹捌零零 報告版本&#xff1a;下單后會更新至最新版本 交貨時間&#xff1a;1-2天 第一章 汽車電子相關概述 1.1 汽車的相關介紹 1.1.1 汽車的概念 我國國家最新標準《汽車和掛車類型的術語和定義》&#xff08;GB/T3730&#xff0e;1—2001&…

基于springboot+vue的貿易行業crm系統

博主主頁&#xff1a;貓頭鷹源碼 博主簡介&#xff1a;Java領域優質創作者、CSDN博客專家、阿里云專家博主、公司架構師、全網粉絲5萬、專注Java技術領域和畢業設計項目實戰&#xff0c;歡迎高校老師\講師\同行交流合作 ?主要內容&#xff1a;畢業設計(Javaweb項目|小程序|Pyt…

Flink分區相關

0、要點 Flink的分區列不會存數據&#xff0c;也就是兩個列有一個分區列&#xff0c;則文件只會存另一個列的數據 1、CreateTable 根據SQL的執行流程&#xff0c;進入TableEnvironmentImpl.executeInternal&#xff0c;createTable分支 } else if (operation instanceof Crea…

Java-nio

一、NIO三大組件 NIO的三大組件分別是Channel&#xff0c;Buffer與Selector Java NIO系統的核心在于&#xff1a;通道(Channel)和緩沖區(Buffer)。通道表示打開到 IO 設備(例如&#xff1a;文件、套接字)的連接。若需要使用 NIO 系統&#xff0c;需要獲取用于連接 IO 設備的通…

Spring的簡單使用及內部實現原理

在現代的Java應用程序開發中&#xff0c;Spring Framework已經成為了不可或缺的工具之一。它提供了一種輕量級的、基于Java的解決方案&#xff0c;用于構建企業級應用程序和服務。本文將介紹Spring的簡單使用方法&#xff0c;并深入探討其內部實現原理。 首先&#xff0c;讓我們…

mysql8.0使用MGR實現高可用

一、三節點MGR集群的安裝部署 1. 安裝準備 準備好下面三臺服務器&#xff1a; IP端口角色192.168.150.213306mgr1192.168.150.223306mgr2192.168.150.233306mgr3 配置hosts解析 # cat >> /etc/hosts << EOF 192.168.150.21 mgr1 192.168.150.22 mgr2 192.168…

Windows環境下的調試器探究——硬件斷點

與軟件斷點與內存斷點不同&#xff0c;硬件斷點不依賴被調試程序&#xff0c;而是依賴于CPU中的調試寄存器。 調試寄存器有7個&#xff0c;分別為Dr0~Dr7。 用戶最多能夠設置4個硬件斷點&#xff0c;這是由于只有Dr0~Dr3用于存儲線性地址。 其中&#xff0c;Dr4和Dr5是保留的…

java中容器繼承體系

首先上圖 源碼解析 打開Collection接口源碼&#xff0c;能夠看到Collection接口是繼承了Iterable接口。 public interface Collection<E> extends Iterable<E> { /** * ...... */ } 以下是Iterable接口源碼及注釋 /** * Implementing this inte…

makefileGDB使用

一、makefile 1、make && makefile makefile帶來的好處就是——自動化編譯&#xff0c;一旦寫好&#xff0c;只需要一個make命令&#xff0c;整個工程完全自動編譯&#xff0c;極大的提高了軟件開發的效率 下面我們通過如下示例來進一步體會它們的作用&#xff1a; ①…

使用 Python 實現一個飛書/微信記賬機器人,酷B了!

Python飛書文檔機器人 今天的主題是&#xff1a;使用Python聯動飛書文檔機器人&#xff0c;實現一個專屬的記賬助手&#xff0c;這篇文章如果對你幫助極大&#xff0c;歡迎你分享給你的朋友、她、他&#xff0c;一起成長。 也歡迎大家留言&#xff0c;說說自己想看什么主題的…

代碼隨想錄第天 78.子集 90.子集II

LeetCode 78 子集 題目描述 給你一個整數數組 nums &#xff0c;數組中的元素 互不相同 。返回該數組所有可能的子集&#xff08;冪集&#xff09;。 解集 不能 包含重復的子集。你可以按 任意順序 返回解集。 示例 1&#xff1a; 輸入&#xff1a;nums [1,2,3] 輸出&…

LeetCode 2581.統計可能的樹根數目:換根DP(樹形DP)

【LetMeFly】2581.統計可能的樹根數目&#xff1a;換根DP(樹形DP) 力扣題目鏈接&#xff1a;https://leetcode.cn/problems/count-number-of-possible-root-nodes/ Alice 有一棵 n 個節點的樹&#xff0c;節點編號為 0 到 n - 1 。樹用一個長度為 n - 1 的二維整數數組 edges…

debian/ubuntu 編譯安裝nginx php

debian/ubuntu 編譯安裝nginx php tar -zxvf nginx-1.9.9.tar.gz apt-get install libpcre3 libpcre3-dev ./configure --prefix/work/nginx-1.9.9 --with-pcre make make install service iptables stop #關閉防火墻, 可能不需要 修改nginx運行用戶為tboqi 抱著log目錄可…

【通信基礎知識】完整通信系統的流程圖及各模塊功能詳解

2024.2.29 抱歉最近在寫畢設大論文&#xff0c;因此沒有太多時間更新。然而&#xff0c;在寫論文的過程中&#xff0c;發現自己對通信系統的了解還不夠全明白&#xff0c;因此差了一些碩博論文總結了一個完整的通信系統流程圖。若有不對的地方請多多指正//部分內容有參考ChatGP…

【Elasticsearch管理】網絡配置

文章目錄 HTTP高級網絡設置高級TCP設置 TransportTCP傳輸概要文件Transport跟蹤 線程池fixed線程池fixed_auto_queue_sizescaling處理器設置 HTTP Elasticsearch只在默認情況下綁定到本地主機。對于運行本地開發服務器(如果在同一臺機器上啟動多個節點&#xff0c;甚至可以運行…

YOLOv7基礎 | 第2種方式:簡化網絡結構之yolov7.yaml(由104層簡化為30層)

前言:Hello大家好,我是小哥談。通過下載YOLOv7源碼可知,原始的yolov7.yaml文件是拆開寫的,比較混亂,也不好理解,并且為后續改進增添了很多困難。基于此種情況,筆者就給大家介紹一種將yolov7.yaml文件簡化的方法,將104層簡化為30層,并且參數量和計算量和原來是一致的,…

內存占用構造方法

#使用虛擬內存構造內存消耗 mkdir /tmp/memory mount -t tmpfs -o size5G tmpfs /tmp/memory dd if/dev/zero of/tmp/memory/block #釋放消耗的虛擬內存 rm -rf /tmp/memory/block umount /tmp/memory rmdir /tmp/memory #內存占用可直接在/dev/shm目錄下寫文件