[C#]winform部署openvino官方提供的人脸检测模型

【官方框架地址】

https://github.com/sdcb/OpenVINO.NET

【框架介绍】

OpenVINO(Open Visual Inference & Neural Network Optimization)是一个由Intel推出的,针对计算机视觉和机器学习任务的开源工具套件。通过优化神经网络,加速深度学习推理,OpenVINO可以帮助开发者更高效地在Intel硬件上部署机器学习应用。

OpenVINO的.NET版本是其与.NET生态系统的结合,提供了C#语言的API接口,让.NET开发者能更容易地集成和使用OpenVINO的功能。.NET开发者可以快速将OpenVINO的优化和加速能力集成到他们的应用中,提高图像和视频处理的速度。

使用OpenVINO.NET,开发者可以:

  1. 优化神经网络:OpenVINO能够优化和转换神经网络模型,使其更适合在Intel硬件上运行。
  2. 加速推理:通过利用Intel硬件的特性,如集成显卡或至强处理器,OpenVINO可以显著提高推理速度。
  3. 简化开发流程:OpenVINO.NET提供了C#语言的API,让开发者能够用他们熟悉的编程语言进行开发,减少了学习和技术门槛。
  4. 丰富的生态系统:与.NET生态系统结合,可以利用现有的.NET框架和库,更容易地构建复杂的应用程序。
  5. 跨平台支持:OpenVINO.NET不仅支持Windows平台,也支持Linux和macOS,使得开发的应用具有更广泛的部署能力。

总的来说,OpenVINO.NET为.NET开发者提供了一个强大的工具,帮助他们快速构建高性能的机器学习和计算机视觉应用。通过优化神经网络和加速推理,OpenVINO.NET有助于推动AI技术在各种行业中的应用和发展。

【效果展示】

【实现部分代码】

复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;

namespace FIRC
{
    public partial class Form1 : Form
    {
        Mat src = new Mat();
        FaceDetector detector = new FaceDetector();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = false;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
              
                src = Cv2.ImRead(openFileDialog.FileName);

                pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);


            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(pictureBox1.Image==null)
            {
                return;
            }

            var result = detector.Inference(src);
            var resultMat = detector.DrawImage(result,src);
            pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            detector.LoadWeights(Application.StartupPath+ "\\weights\\face-detection-0200.xml");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            VideoCapture capture = new VideoCapture(0);
            if (!capture.IsOpened())
            {
                Console.WriteLine("video not open!");
                return;
            }
            Mat frame = new Mat();
            var sw = new Stopwatch();
            int fps = 0;
            while (true)
            {

                capture.Read(frame);
                if (frame.Empty())
                {
                    Console.WriteLine("data is empty!");
                    break;
                }
                sw.Start();
                var result = detector.Inference(src);
                var resultMat = detector.DrawImage(result, src);
                sw.Stop();
                fps = Convert.ToInt32(1 / sw.Elapsed.TotalSeconds);
                sw.Reset();
                Cv2.PutText(resultMat, "FPS=" + fps, new OpenCvSharp.Point(30, 30), HersheyFonts.HersheyComplex, 1.0, new Scalar(255, 0, 0), 3);
                //显示结果
                Cv2.ImShow("Result", resultMat);
                int key = Cv2.WaitKey(10);
                if (key == 27)
                    break;
            }

            capture.Release();
        }
    }
}

【视频演示】

https://www.bilibili.com/video/BV1wV411973m/?vd_source=989ae2b903ea1b5acebbe2c4c4a635ee

【测试环境】

vs2019,netframework4.7.2

相关推荐
好奇龙猫19 小时前
【人工智能学习-AI-MIT公开课第 16 讲:支持向量机(SVM)】
人工智能·学习·支持向量机
环黄金线HHJX.19 小时前
【MCP: Tuan编程 + Qt架构 + QoS - 量子-经典混合计算管理控制平台】
ide·人工智能·qt·编辑器·量子计算
duyinbi751719 小时前
【环境监测】河流目标检测:建筑物、树木和水轮机识别实战
人工智能·目标检测·计算机视觉
cute_ming19 小时前
浅谈提示词工程:企业级系统化实践与自动化架构(三)
人工智能·ubuntu·机器学习·架构·自动化
PHOSKEY19 小时前
QM系列闪测仪在医用核心原材料(TC4/PEEK/ 硅胶)质控方案
人工智能·机器学习
WJSKad123519 小时前
【狮子目标检测】YOLO13-GhostDynamicConv改进模型实现与性能分析
人工智能·目标检测·计算机视觉
Toky丶20 小时前
【文献阅读】ARB-LLM: Alternating Refined Binarizations for Large Language Models
人工智能·语言模型·自然语言处理
斯外戈的小白20 小时前
【NLP】Hugging Face使用指南
人工智能·自然语言处理
victory043120 小时前
关于深度学习的重要库 transformer
人工智能·深度学习·transformer
love530love20 小时前
Flash Attention 2.8.3 在 Windows + RTX 3090 上成功编译与运行复盘笔记(2026年1月版)
人工智能·windows·笔记·python·flash_attn·flash attention·z-image