最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# Onnx實(shí)現(xiàn)輕量實(shí)時(shí)的M-LSD直線檢測(cè)

 更新時(shí)間:2023年11月15日 10:19:16   作者:天天代碼碼天天  
這篇文章主要為大家詳細(xì)介紹了C#如何結(jié)合Onnx實(shí)現(xiàn)輕量實(shí)時(shí)的M-LSD直線檢測(cè),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

介紹

github地址:https://github.com/navervision/mlsd 

M-LSD: Towards Light-weight and Real-time Line Segment Detection
Official Tensorflow implementation of "M-LSD: Towards Light-weight and Real-time Line Segment Detection" (AAAI 2022 Oral session)

Geonmo Gu*, Byungsoo Ko*, SeoungHyun Go, Sung-Hyun Lee, Jingeun Lee, Minchul Shin (* Authors contributed equally.)

First figure: Comparison of M-LSD and existing LSD methods on GPU. Second figure: Inference speed and memory usage on mobile devices.

We present a real-time and light-weight line segment detector for resource-constrained environments named Mobile LSD (M-LSD). M-LSD exploits extremely efficient LSD architecture and novel training schemes, including SoL augmentation and geometric learning scheme. Our model can run in real-time on GPU, CPU, and even on mobile devices.

效果

效果1

效果2

效果3

效果4

模型信息

Inputs
-------------------------
name:input_image_with_alpha:0
tensor:Float[1, 512, 512, 4]
---------------------------------------------------------------

Outputs
-------------------------
name:Identity
tensor:Int32[1, 200, 2]
name:Identity_1
tensor:Float[1, 200]
name:Identity_2
tensor:Float[1, 256, 256, 4]
---------------------------------------------------------------

項(xiàng)目

VS2022

.net framework 4.8

OpenCvSharp 4.8

Microsoft.ML.OnnxRuntime 1.16.2

代碼

using Microsoft.ML.OnnxRuntime.Tensors;
using Microsoft.ML.OnnxRuntime;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using System.Drawing;
 
namespace Onnx_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
 
        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
 
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
 
        int inpWidth;
        int inpHeight;
 
        Mat image;
 
        string model_path = "";
 
        SessionOptions options;
        InferenceSession onnx_session;
        Tensor<float> input_tensor;
        Tensor<float> mask_tensor;
        List<NamedOnnxValue> input_ontainer;
 
        IDisposableReadOnlyCollection<DisposableNamedOnnxValue> result_infer;
        DisposableNamedOnnxValue[] results_onnxvalue;
 
        float conf_threshold = 0.5f;
        float dist_threshold = 20.0f;
 
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
 
            pictureBox1.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";
 
            image_path = ofd.FileName;
            pictureBox1.Image = new System.Drawing.Bitmap(image_path);
            image = new Mat(image_path);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
            // 創(chuàng)建輸入容器
            input_ontainer = new List<NamedOnnxValue>();
 
            // 創(chuàng)建輸出會(huì)話
            options = new SessionOptions();
            options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;
            options.AppendExecutionProvider_CPU(0);// 設(shè)置為CPU上運(yùn)行
 
            // 創(chuàng)建推理模型類(lèi),讀取本地模型文件
            model_path = "model/model_512x512_large.onnx";
 
            inpWidth = 512;
            inpHeight = 512;
            onnx_session = new InferenceSession(model_path, options);
 
            // 創(chuàng)建輸入容器
            input_ontainer = new List<NamedOnnxValue>();
 
            image_path = "test_img/4.jpg";
            pictureBox1.Image = new Bitmap(image_path);
 
        }
 
        private unsafe void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "檢測(cè)中,請(qǐng)稍等……";
            pictureBox2.Image = null;
            System.Windows.Forms.Application.DoEvents();
 
            image = new Mat(image_path);
 
            Mat resize_image = new Mat();
            Cv2.Resize(image, resize_image, new OpenCvSharp.Size(512, 512));
 
            float h_ratio = (float)image.Rows / 512;
            float w_ratio = (float)image.Cols / 512;
 
            int row = resize_image.Rows;
            int col = resize_image.Cols;
            float[] input_tensor_data = new float[1 * 4 * row * col];
            int k = 0;
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    for (int c = 0; c < 3; c++)
                    {
                        float pix = ((byte*)(resize_image.Ptr(i).ToPointer()))[j * 3 + c];
                        input_tensor_data[k] = pix;
                        k++;
                    }
                    input_tensor_data[k] = 1;
                    k++;
                }
            }
 
            input_tensor = new DenseTensor<float>(input_tensor_data, new[] { 1, 512, 512, 4 });
 
            //將 input_tensor 放入一個(gè)輸入?yún)?shù)的容器,并指定名稱(chēng)
            input_ontainer.Add(NamedOnnxValue.CreateFromTensor("input_image_with_alpha:0", input_tensor));
 
            dt1 = DateTime.Now;
            //運(yùn)行 Inference 并獲取結(jié)果
            result_infer = onnx_session.Run(input_ontainer);
            dt2 = DateTime.Now;
 
            //將輸出結(jié)果轉(zhuǎn)為DisposableNamedOnnxValue數(shù)組
            results_onnxvalue = result_infer.ToArray();
 
            int[] pts = results_onnxvalue[0].AsTensor<int>().ToArray();
            float[] pts_score = results_onnxvalue[1].AsTensor<float>().ToArray();
            float[] vmap = results_onnxvalue[2].AsTensor<float>().ToArray();
            List<List<int>> segments_list = new List<List<int>>();
            int num_lines = 200;
            int map_h = 256;
            int map_w = 256;
 
            for (int i = 0; i < num_lines; i++)
            {
                int y = pts[i * 2];
                int x = pts[i * 2 + 1];
 
                float disp_x_start = vmap[0 + y * map_w * 4 + x * 4];
                float disp_y_start = vmap[1 + y * map_w * 4 + x * 4];
                float disp_x_end = vmap[2 + y * map_w * 4 + x * 4];
                float disp_y_end = vmap[3 + y * map_w * 4 + x * 4];
 
                float distance = (float)Math.Sqrt(Math.Pow(disp_x_start - disp_x_end, 2) + Math.Pow(disp_y_start - disp_y_end, 2));
 
                if (pts_score[i] > conf_threshold && distance > dist_threshold)
                {
                    float x_start = (x + disp_x_start) * 2 * w_ratio;
                    float y_start = (y + disp_y_start) * 2 * h_ratio;
                    float x_end = (x + disp_x_end) * 2 * w_ratio;
                    float y_end = (y + disp_y_end) * 2 * h_ratio;
                    List<int> line = new List<int>() { (int)x_start, (int)y_start, (int)x_end, (int)y_end };
                    segments_list.Add(line);
                }
            }
 
            Mat result_image = image.Clone();
            for (int i = 0; i < segments_list.Count; i++)
            {
                Cv2.Line(result_image, new OpenCvSharp.Point(segments_list[i][0], segments_list[i][1]), new OpenCvSharp.Point(segments_list[i][2], segments_list[i][3]), new Scalar(0, 0, 255), 3);
            }
 
            pictureBox2.Image = new System.Drawing.Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "推理耗時(shí):" + (dt2 - dt1).TotalMilliseconds + "ms";
        }
 
        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }
 
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}

其他

結(jié)合透視變換可實(shí)現(xiàn)圖像校正,圖像校正參考

C#使用OpenCvSharp實(shí)現(xiàn)圖像校正

C#使用OpenCvSharp實(shí)現(xiàn)透視變換

以上就是C# Onnx實(shí)現(xiàn)輕量實(shí)時(shí)的M-LSD直線檢測(cè)的詳細(xì)內(nèi)容,更多關(guān)于C#直線檢測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C#延遲執(zhí)行方法函數(shù)實(shí)例講解

    C#延遲執(zhí)行方法函數(shù)實(shí)例講解

    這篇文章主要介紹了C#延遲執(zhí)行方法函數(shù)實(shí)例講解,這是比較常用的函數(shù),有需要的同學(xué)可以研究下
    2021-03-03
  • C# Color.FromArgb()及系統(tǒng)顏色對(duì)照表一覽

    C# Color.FromArgb()及系統(tǒng)顏色對(duì)照表一覽

    這篇文章主要介紹了C# Color.FromArgb()及系統(tǒng)顏色對(duì)照表一覽,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • c# 重載WndProc,實(shí)現(xiàn)重寫(xiě)“最小化”的實(shí)現(xiàn)方法

    c# 重載WndProc,實(shí)現(xiàn)重寫(xiě)“最小化”的實(shí)現(xiàn)方法

    在做“亦歌桌面版”的時(shí)候,發(fā)現(xiàn)當(dāng)打開(kāi)歌詞狀態(tài)下,用最小化隱藏窗體到托盤(pán)的話(如下code #1),在調(diào)出發(fā)現(xiàn)歌詞縮小了(雖然顯現(xiàn)的窗體大小跟剛才一樣),從這點(diǎn)看調(diào)用該方法其實(shí)窗體大小是改變了的(這個(gè)過(guò)程只是不可視而已)。
    2009-02-02
  • Unity中協(xié)程IEnumerator的使用方法介紹詳解

    Unity中協(xié)程IEnumerator的使用方法介紹詳解

    本文主要介紹了Unity中協(xié)程IEnumerator的使用方法介紹詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • 基于C#實(shí)現(xiàn)文檔打印功能

    基于C#實(shí)現(xiàn)文檔打印功能

    在軟件開(kāi)發(fā)過(guò)程中,文檔打印是一個(gè)常見(jiàn)的功能需求,本文將詳細(xì)介紹如何在C#中實(shí)現(xiàn)文檔打印,并通過(guò)代碼示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定幫助,需要的朋友可以參考下
    2024-10-10
  • C#將時(shí)間轉(zhuǎn)成文件名使用方法

    C#將時(shí)間轉(zhuǎn)成文件名使用方法

    C#將時(shí)間轉(zhuǎn)成文件名用到的是DateTime類(lèi)的ToFileTime方法,下面看使用方法吧
    2014-01-01
  • C#日期格式化的幾個(gè)要點(diǎn)小結(jié)

    C#日期格式化的幾個(gè)要點(diǎn)小結(jié)

    本文將介紹C#日期格式化的幾個(gè)要點(diǎn),包括標(biāo)準(zhǔn) DateTime 格式字符串。希望大家能從中得到更多的理解和幫助
    2013-09-09
  • C#通過(guò)反射打開(kāi)相應(yīng)窗體方法分享

    C#通過(guò)反射打開(kāi)相應(yīng)窗體方法分享

    本文章來(lái)給各位同學(xué)介紹關(guān)于C#單擊菜單欄或工具欄時(shí)通過(guò)反射打開(kāi)窗體的方法,有需要了解的朋友可進(jìn)入?yún)⒖紖⒖肌?/div> 2015-05-05
  • 基于C#實(shí)現(xiàn)SM2加簽驗(yàn)簽工具

    基于C#實(shí)現(xiàn)SM2加簽驗(yàn)簽工具

    這篇文章主要為大家詳細(xì)介紹了如何基于C#實(shí)現(xiàn)一個(gè)SM2加簽驗(yàn)簽工具,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-10-10
  • RabbitMQ的配置與安裝教程全紀(jì)錄

    RabbitMQ的配置與安裝教程全紀(jì)錄

    這篇文章主要給大家介紹了關(guān)于RabbitMQ的配置與安裝的相關(guān)資料,文中通過(guò)示例代碼以及圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07

最新評(píng)論

抚顺市| 玛纳斯县| 和静县| 池州市| 宁海县| 朝阳区| 华容县| 施秉县| 新河县| 军事| 黔东| 顺平县| 基隆市| 尉犁县| 余庆县| 廉江市| 嘉义县| 拉萨市| 荥经县| 广丰县| 井冈山市| 永州市| 蒙山县| 武隆县| 遂昌县| 西盟| 马山县| 汨罗市| 巨野县| 台东县| 婺源县| 萨迦县| 抚顺县| 内江市| 康保县| 濮阳县| 伽师县| 鹤岗市| 重庆市| 吕梁市| 汝州市|