欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2024年02月05日 10:14:50   作者:天天代碼碼天天  
這篇文章主要為大家詳細(xì)介紹了C#?OpenVINO如何實(shí)現(xiàn)圖片旋轉(zhuǎn)角度檢測,文中的示例代碼講解詳細(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)角度檢測
{
    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)角度檢測的詳細(xì)內(nèi)容,更多關(guān)于C# OpenVINO圖片旋轉(zhuǎn)角度檢測的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Unity實(shí)現(xiàn)注冊登錄模塊

    Unity實(shí)現(xiàn)注冊登錄模塊

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)注冊登錄模塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • 使用C#實(shí)現(xiàn)上位機(jī)與PLC通信的過程詳解

    使用C#實(shí)現(xiàn)上位機(jī)與PLC通信的過程詳解

    隨著工業(yè)自動化技術(shù)的不斷發(fā)展,PLC(可編程邏輯控制器)已成為現(xiàn)代生產(chǎn)過程中不可或缺的設(shè)備,為了實(shí)現(xiàn)設(shè)備之間的數(shù)據(jù)交換和遠(yuǎn)程控制,上位機(jī)系統(tǒng)需要與PLC進(jìn)行通信,在本文中,我們將從零開始,介紹如何使用C#實(shí)現(xiàn)上位機(jī)與PLC的通信,需要的朋友可以參考下
    2025-01-01
  • vscode編寫latex的方法

    vscode編寫latex的方法

    這篇文章主要介紹了vscode編寫latex的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-07-07
  • 簡介C#讀取XML的兩種方式

    簡介C#讀取XML的兩種方式

    在程序中訪問進(jìn)而操作XML文件一般有兩種模型,分別是使用DOM(文檔對象模型)和流模型,使用DOM的好處在于它允許編輯和更新XML文檔,可以隨機(jī)訪問文檔中的數(shù)據(jù),可以使用XPath查詢
    2013-03-03
  • C#打包應(yīng)用程序,與.NETFramework介紹

    C#打包應(yīng)用程序,與.NETFramework介紹

    C#打包應(yīng)用程序,與.NETFramework介紹,需要的朋友可以參考一下
    2013-05-05
  • C#/VB.NET創(chuàng)建PDF文檔的示例代碼

    C#/VB.NET創(chuàng)建PDF文檔的示例代碼

    通過代碼創(chuàng)建 PDF 文檔有許多好處,所以本文將為大家詳細(xì)介紹一下如何使用 Spire.PDF for .NET 在 C# 和 VB.NET 中從頭開始創(chuàng)建 PDF 文檔,需要的可以參考下
    2023-12-12
  • WCF的異常處理

    WCF的異常處理

    這篇文章介紹了WCF處理異常的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • C#實(shí)現(xiàn)給圖片加水印的方法

    C#實(shí)現(xiàn)給圖片加水印的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)給圖片加水印的方法,結(jié)合完整實(shí)例形式分析了C#常見的圖片水印操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-02-02
  • C#獲取日期的星期名稱實(shí)例代碼

    C#獲取日期的星期名稱實(shí)例代碼

    本文通過實(shí)例代碼給大家介紹了基于c#獲取日期的星期名稱,代碼簡單易懂,非常不錯,具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2018-08-08
  • C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解

    C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解

    這篇文章主要介紹了C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-10-10

最新評論