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

C# Onnx實(shí)現(xiàn)特征匹配DeDoDe檢測(cè)

 更新時(shí)間:2023年11月22日 10:53:04   作者:天天代碼碼天天  
這篇文章主要為大家詳細(xì)介紹了C# Onnx如何實(shí)現(xiàn)特征匹配DeDoDe檢測(cè),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

介紹

github地址:https://github.com/Parskatt/DeDoDe

DeDoDe ?? Detect, Don't Describe - Describe, Don't Detect, for Local Feature Matching

The DeDoDe detector learns to detect 3D consistent repeatable keypoints, which the DeDoDe descriptor learns to match. The result is a powerful decoupled local feature matcher.

Training DeDoDe

DISCLAMER: I've (Johan) not yet tested that the training scripts here reproduces our original results. This repo is very similar to the internal training repo, but there might be bugs introduced by refactoring etc. Let me know if you face any issues reproducing our results (or if you somehow get better results :D).

See experiments for the scripts to train DeDoDe. We trained on a single A100-40GB with a batchsize of 8. Note that you need to do the data prep first, see data_prep.

As usual, we require that you have the MegaDepth dataset already downloaded, and that you have the prepared scene info from DKM.

效果

模型信息

Inputs
-------------------------
name:images
tensor:Float[-1, 3, -1, -1]
---------------------------------------------------------------

Outputs
-------------------------
name:matches_A
tensor:Float[-1, -1]
name:matches_B
tensor:Float[-1, -1]
name:batch_ids
tensor:Int64[-1]
---------------------------------------------------------------

項(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;
using static System.Net.Mime.MediaTypeNames;
using System.Numerics;
 
namespace Onnx_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
 
        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        string image_path2 = "";
 
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
 
        int inpWidth;
        int inpHeight;
 
        float[] mean =new float[] { 0.485f, 0.456f, 0.406f };
        float[] std = new float[] { 0.229f, 0.224f, 0.225f };
 
        Mat image;
        Mat image2;
 
        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;
 
        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)建推理模型類,讀取本地模型文件
            model_path = "model/dedode_end2end_1024.onnx";
 
            inpHeight = 256;
            inpWidth = 256;
 
            onnx_session = new InferenceSession(model_path, options);
 
            // 創(chuàng)建輸入容器
            input_ontainer = new List<NamedOnnxValue>();
 
            image_path = "test_img/im_A.jpg";
            pictureBox1.Image = new Bitmap(image_path);
 
            image_path2 = "test_img/im_B.jpg";
            pictureBox3.Image = new Bitmap(image_path2);
 
        }
 
        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);
            image2 = new Mat(image_path2);
 
            float[] input_tensor_data = new float[2 * 3 * inpWidth * inpHeight];
 
            //preprocess
            Mat dstimg = new Mat();
            Cv2.CvtColor(image, dstimg, ColorConversionCodes.BGR2RGB);
            Cv2.Resize(dstimg, dstimg, new OpenCvSharp.Size(inpWidth, inpHeight));
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < inpHeight; i++)
                {
                    for (int j = 0; j < inpWidth; j++)
                    {
                        float pix = ((byte*)(dstimg.Ptr(i).ToPointer()))[j * 3 + c];
                        input_tensor_data[c * inpWidth * inpHeight + i * inpWidth + j] = (float)((pix / 255.0 - mean[c]) / std[c]);
                    }
                }
            }
 
            Cv2.CvtColor(image2, dstimg, ColorConversionCodes.BGR2RGB);
            Cv2.Resize(dstimg, dstimg, new OpenCvSharp.Size(inpWidth, inpHeight));
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < inpHeight; i++)
                {
                    for (int j = 0; j < inpWidth; j++)
                    {
                        float pix = ((byte*)(dstimg.Ptr(i).ToPointer()))[j * 3 + c];
                        input_tensor_data[(3+c )* inpWidth * inpHeight + i * inpWidth + j] = (float)((pix / 255.0 - mean[c]) / std[c]);
                    }
                }
            }
 
            input_tensor = new DenseTensor<float>(input_tensor_data, new[] { 2, 3, inpHeight, inpWidth });
 
            //將 input_tensor 放入一個(gè)輸入?yún)?shù)的容器,并指定名稱
            input_ontainer.Add(NamedOnnxValue.CreateFromTensor("images", input_tensor));
 
            dt1 = DateTime.Now;
            //運(yùn)行 Inference 并獲取結(jié)果
            result_infer = onnx_session.Run(input_ontainer);
            dt2 = DateTime.Now;
 
            //Postprocessing
            //將輸出結(jié)果轉(zhuǎn)為DisposableNamedOnnxValue數(shù)組
            results_onnxvalue = result_infer.ToArray();
 
            float[] matches_A = results_onnxvalue[0].AsTensor<float>().ToArray();
            float[] matches_B = results_onnxvalue[1].AsTensor<float>().ToArray();
            int num_points = results_onnxvalue[0].AsTensor<float>().Dimensions[0];
 
            List<KeyPoint> points_A = new List<KeyPoint>();
            List<KeyPoint> points_B = new List<KeyPoint>();
 
            KeyPoint temp;
            for (int i = 0; i < num_points; i++)
            {
                temp = new KeyPoint();
                temp.Pt.X = (float)((matches_A[i * 2] + 1) * 0.5 * image.Cols);
                temp.Pt.Y = (float)((matches_A[i * 2 + 1] + 1) * 0.5 * image.Rows);
                temp.Size = 1f;
                points_A.Add(temp);
            }
 
            num_points = results_onnxvalue[1].AsTensor<float>().Dimensions[0];
            for (int i = 0; i < num_points; i++)
            {
                temp = new KeyPoint();
                temp.Pt.X = (float)((matches_B[i * 2] + 1) * 0.5 * image2.Cols);
                temp.Pt.Y = (float)((matches_B[i * 2 + 1] + 1) * 0.5 * image2.Rows);
                temp.Size = 1f;
                points_B.Add(temp);
            }
 
            //匹配結(jié)果放在matches里面
            num_points = points_A.Count();
            List<DMatch> matches=new List<DMatch>();
            for (int i = 0; i < num_points; i++)
            {
                matches.Add(new DMatch(i, i, 0f));
            }
 
            //按照匹配關(guān)系將圖畫出來,背景圖為match_img
            Mat match_img = new Mat();
            Cv2.DrawMatches(image, points_A, image2, points_B, matches, match_img);
 
            pictureBox2.Image = new System.Drawing.Bitmap(match_img.ToMemoryStream());
            textBox1.Text = "推理耗時(shí):" + (dt2 - dt1).TotalMilliseconds + "ms";
 
        }
 
        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
 
            pictureBox3.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";
 
            image_path2 = ofd.FileName;
            pictureBox3.Image = new System.Drawing.Bitmap(image_path2);
            image2 = new Mat(image_path2);
        }
 
        private void pictureBox3_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox3.Image);
        }
 
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}

到此這篇關(guān)于C# Onnx實(shí)現(xiàn)特征匹配DeDoDe檢測(cè)的文章就介紹到這了,更多相關(guān)C# Onnx特征匹配內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • c#中DateTime.Now函數(shù)的使用詳解

    c#中DateTime.Now函數(shù)的使用詳解

    本篇文章對(duì)c#中DateTime.Now函數(shù)的使用進(jìn)行了介紹。需要的朋友參考下
    2013-05-05
  • 微信開發(fā)--企業(yè)轉(zhuǎn)賬到用戶

    微信開發(fā)--企業(yè)轉(zhuǎn)賬到用戶

    本文主要介紹了微信開發(fā)--企業(yè)轉(zhuǎn)賬到用戶的實(shí)現(xiàn)方法與步驟。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-01-01
  • C#編寫游戲客戶端的實(shí)現(xiàn)代碼

    C#編寫游戲客戶端的實(shí)現(xiàn)代碼

    這篇文章主要介紹了C#編寫游戲客戶端的實(shí)現(xiàn)代碼,連接客戶端原理流程圖,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-11-11
  • C#實(shí)現(xiàn)金額轉(zhuǎn)換成中文大寫金額

    C#實(shí)現(xiàn)金額轉(zhuǎn)換成中文大寫金額

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)金額轉(zhuǎn)換成中文大寫金額,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • C# DirectShow預(yù)覽攝像頭并截圖

    C# DirectShow預(yù)覽攝像頭并截圖

    這篇文章主要為大家詳細(xì)介紹了C# DirectShow預(yù)覽攝像頭并截圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • 淺談c#中config.exe 引發(fā)的一些問題

    淺談c#中config.exe 引發(fā)的一些問題

    下面小編就為大家分享一篇淺談c#中config.exe 引發(fā)的一些問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2017-11-11
  • C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式

    C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式

    這篇文章主要介紹了C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • C#使用 NAudio 實(shí)現(xiàn)音頻可視化的方法

    C#使用 NAudio 實(shí)現(xiàn)音頻可視化的方法

    這篇文章主要介紹了[C#] 使用 NAudio 實(shí)現(xiàn)音頻可視化的相關(guān)資料,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-05-05
  • c#實(shí)現(xiàn)多線程局域網(wǎng)聊天系統(tǒng)

    c#實(shí)現(xiàn)多線程局域網(wǎng)聊天系統(tǒng)

    這篇文章主要介紹了c#實(shí)現(xiàn)多線程局域網(wǎng)聊天系統(tǒng)的相關(guān)代碼,有此方面需求的小伙伴可以參考下。
    2015-06-06
  • 詳解C#如何使用消息隊(duì)列MSMQ

    詳解C#如何使用消息隊(duì)列MSMQ

    消息隊(duì)列 (MSMQ Microsoft Message Queuing)是MS提供的服務(wù),也就是Windows操作系統(tǒng)的功能,下面就跟隨小編一起了解一下C#中是如何使用消息隊(duì)列MSMQ的吧
    2024-01-01

最新評(píng)論

达日县| 怀集县| 峨山| 遂昌县| 黄浦区| 仁怀市| 祁东县| 张家港市| 嫩江县| 宝鸡市| 波密县| 定远县| 中超| 建昌县| 五指山市| 吴江市| 连平县| 衡山县| 海淀区| 亚东县| 炎陵县| 丹东市| 宜良县| 辽中县| 东乡族自治县| 榆社县| 郴州市| 西充县| 图片| 马关县| 红桥区| 定州市| 得荣县| 鲜城| 康保县| 舒城县| 墨脱县| 读书| 黑龙江省| 淳化县| 邵阳县|