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

C# OpenVINO實(shí)現(xiàn)圖片旋轉(zhuǎn)角度檢測(cè)

 更新時(shí)間:2024年02月05日 10:14:50   作者:天天代碼碼天天  
這篇文章主要為大家詳細(xì)介紹了C#?OpenVINO如何實(shí)現(xiàn)圖片旋轉(zhuǎn)角度檢測(cè),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

效果

項(xiàng)目

代碼

using OpenCvSharp;
using Sdcb.OpenVINO;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
 
namespace C__OpenVINO_圖片旋轉(zhuǎn)角度檢測(cè)
{
    public partial class Form1 : Form
    {
        Bitmap bmp;
        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string img = "";
        float rotateThreshold = 0.50f;
        InputShape defaultShape = new InputShape(3, 224, 224);
        string model_path;
        CompiledModel cm;
        InferRequest ir;
 
        StringBuilder sb = new StringBuilder();
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            model_path = "models/inference.pdmodel";
            Model rawModel = OVCore.Shared.ReadModel(model_path);
 
            var ad = OVCore.Shared.AvailableDevices;
            Console.WriteLine("可用設(shè)備");
            foreach (var item in ad)
            {
                Console.WriteLine(item);
            }
 
            cm = OVCore.Shared.CompileModel(rawModel, "CPU");
            ir = cm.CreateInferRequest();
 
            img = "1.jpg";
            bmp = new Bitmap(img);
            pictureBox1.Image = new Bitmap(img);
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
 
            pictureBox1.Image = null;
 
            img = ofd.FileName;
            bmp = new Bitmap(img);
            pictureBox1.Image = new Bitmap(img);
            textBox1.Text = "";
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            if (bmp == null)
            {
                return;
            }
 
            var mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bmp);
            Cv2.CvtColor(mat, mat, ColorConversionCodes.RGBA2RGB);
            Cv2.Rotate(mat, mat, RotateFlags.Rotate90Clockwise);
            var bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
            pictureBox1.Image = bitmap;
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            if (bmp == null)
            {
                return;
            }
 
            var mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bmp);
            Cv2.CvtColor(mat, mat, ColorConversionCodes.RGBA2RGB);
            Cv2.Rotate(mat, mat, RotateFlags.Rotate180);
            var bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
            pictureBox1.Image = bitmap;
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            if (bmp == null)
            {
                return;
            }
 
            var mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bmp);
            Cv2.CvtColor(mat, mat, ColorConversionCodes.RGBA2RGB);
            Cv2.Rotate(mat, mat, RotateFlags.Rotate90Counterclockwise);
            var bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
            pictureBox1.Image = bitmap;
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (img == "") { return; }
 
            textBox1.Text = "";
            sb.Clear();
 
            Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(new Bitmap(pictureBox1.Image));
            Cv2.CvtColor(src, src, ColorConversionCodes.RGBA2RGB);//mat轉(zhuǎn)三通道m(xù)at
 
            Stopwatch stopwatch = new Stopwatch();
 
            Mat resized = Common.ResizePadding(src, defaultShape);
            Mat normalized = Common.Normalize(resized);
 
            float[] input_tensor_data = Common.ExtractMat(normalized);
 
            Tensor input_x = Tensor.FromArray(input_tensor_data, new Shape(1, 3, 224, 224));
 
            ir.Inputs[0] = input_x;
 
            double preprocessTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Restart();
 
            ir.Run();
 
            double inferTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Restart();
 
            Tensor output_0 = ir.Outputs[0];
 
            RotationDegree r = RotationDegree._0;
 
            float[] softmax = output_0.GetData<float>().ToArray();
            float max = softmax.Max();
            int maxIndex = Array.IndexOf(softmax, max);
 
            if (max > rotateThreshold)
            {
                r = (RotationDegree)maxIndex;
            }
 
            string result = r.ToString();
 
            result = result + " (" + max.ToString("P2")+")";
 
            double postprocessTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Stop();
            double totalTime = preprocessTime + inferTime + postprocessTime;
 
            sb.AppendLine("結(jié)果:" + result);
            sb.AppendLine();
            sb.AppendLine("Scores: [" + String.Join(", ", softmax) + "]");
            sb.AppendLine();
            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();
 
        }
 
    }
 
    public readonly struct InputShape
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="InputShape"/> struct.
        /// </summary>
        /// <param name="channel">The number of color channels in the input image.</param>
        /// <param name="width">The width of the input image in pixels.</param>
        /// <param name="height">The height of the input image in pixels.</param>
        public InputShape(int channel, int width, int height)
        {
            Channel = channel;
            Height = height;
            Width = width;
        }
 
        /// <summary>
        /// Gets the number of color channels in the input image.
        /// </summary>
        public int Channel { get; }
 
        /// <summary>
        /// Gets the height of the input image in pixels.
        /// </summary>
        public int Height { get; }
 
        /// <summary>
        /// Gets the width of the input image in pixels.
        /// </summary>
        public int Width { get; }
    }
 
    /// <summary>
    /// Enum representing the degrees of rotation.
    /// </summary>
    public enum RotationDegree
    {
        /// <summary>
        /// Represents the 0-degree rotation angle.
        /// </summary>
        _0,
        /// <summary>
        /// Represents the 90-degree rotation angle.
        /// </summary>
        _90,
        /// <summary>
        /// Represents the 180-degree rotation angle.
        /// </summary>
        _180,
        /// <summary>
        /// Represents the 270-degree rotation angle.
        /// </summary>
        _270,
    }
}

以上就是C# OpenVINO實(shí)現(xiàn)圖片旋轉(zhuǎn)角度檢測(cè)的詳細(xì)內(nèi)容,更多關(guān)于C# OpenVINO圖片旋轉(zhuǎn)角度檢測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C#中事件只能在內(nèi)部調(diào)用的原因分析

    C#中事件只能在內(nèi)部調(diào)用的原因分析

    事件(Event)?基本上說(shuō)是一個(gè)用戶操作,如按鍵、點(diǎn)擊、鼠標(biāo)移動(dòng)等等,或者是一些提示信息,如系統(tǒng)生成的通知。應(yīng)用程序需要在事件發(fā)生時(shí)響應(yīng)事件,這篇文章主要介紹了C#中事件為什么只能在內(nèi)部調(diào)用,需要的朋友可以參考下
    2021-11-11
  • DevExpress實(shí)現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點(diǎn)

    DevExpress實(shí)現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點(diǎn)

    這篇文章主要介紹了DevExpress實(shí)現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點(diǎn),需要的朋友可以參考下
    2014-08-08
  • C#實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能(1)(窗體應(yīng)用)

    C#實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能(1)(窗體應(yīng)用)

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡(jiǎn)易計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • c# 如何用組合替代繼承

    c# 如何用組合替代繼承

    這篇文章主要介紹了c# 如何用組合替代繼承,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-02-02
  • C#使用NAudio實(shí)現(xiàn)監(jiān)聽(tīng)系統(tǒng)聲音

    C#使用NAudio實(shí)現(xiàn)監(jiān)聽(tīng)系統(tǒng)聲音

    這篇文章主要為大家詳細(xì)介紹了C#如何使用NAudio實(shí)現(xiàn)監(jiān)聽(tīng)系統(tǒng)聲音并屏蔽麥克風(fēng)其他聲音,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考下
    2024-02-02
  • 深入c# Func委托的詳解

    深入c# Func委托的詳解

    本篇文章是對(duì)c#中的Func委托進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • C#窗體讀取EXCEL并存入SQL數(shù)據(jù)庫(kù)的方法

    C#窗體讀取EXCEL并存入SQL數(shù)據(jù)庫(kù)的方法

    這篇文章主要介紹了C#窗體讀取EXCEL并存入SQL數(shù)據(jù)庫(kù)的方法,實(shí)例簡(jiǎn)述了實(shí)現(xiàn)讀取excel及寫(xiě)入SQL數(shù)據(jù)庫(kù)的原理與技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • C#使用Spire.Doc刪除Word中表格的常用方法

    C#使用Spire.Doc刪除Word中表格的常用方法

    在處理Word文檔自動(dòng)化時(shí),經(jīng)常需要?jiǎng)討B(tài)刪除特定表格使用Spire.Doc,只需幾行C#代碼即可精準(zhǔn)定位并刪除指定表格,無(wú)需手動(dòng)操作,極大提升文檔處理效率,所以本文給大家介紹了如何使用 Spire.Doc 刪除 Word 中的表格,需要的朋友可以參考下
    2025-08-08
  • C#?Sqlite數(shù)據(jù)庫(kù)的搭建及使用技巧

    C#?Sqlite數(shù)據(jù)庫(kù)的搭建及使用技巧

    這篇文章主要介紹了C#?Sqlite數(shù)據(jù)庫(kù)的搭建及使用技巧,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-08-08
  • C#獲取網(wǎng)頁(yè)HTML源碼實(shí)例

    C#獲取網(wǎng)頁(yè)HTML源碼實(shí)例

    這篇文章主要介紹了C#獲取網(wǎng)頁(yè)HTML源碼的方法,是非常實(shí)用的技巧,需要的朋友可以參考下
    2014-10-10

最新評(píng)論

英超| 湖州市| 武邑县| 无锡市| 太和县| 德清县| 望城县| 富裕县| 沅陵县| 棋牌| 措美县| 沅陵县| 五家渠市| 苍南县| 淳化县| 孝义市| 东丰县| 金阳县| 贵州省| 万荣县| 屏东县| 池州市| 涟水县| 彰化市| 肇东市| 桂东县| 吉隆县| 海阳市| 台山市| 斗六市| 石阡县| 沂南县| 乌审旗| 门头沟区| 体育| 措勤县| 延边| 库尔勒市| 汝城县| 杭锦旗| 财经|