[C#]利用opencvsharp实现深度学习caffe模型人脸检测

【官方框架地址】

https://github.com/opencv/opencv/blob/master/samples/dnn/face_detector/deploy.prototxt

采用的是官方caffe模型res10_300x300_ssd_iter_140000.caffemodel进行人脸检测

【算法原理】

使用caffe-ssd目标检测框架训练的caffe模型进行深度学习模型检测

【效果】

【实现部分代码】

复制代码
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 fd = 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 = fd.Inference(src);
            var resultMat = fd.DrawImage(src, result);
            pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
      
       
        }
    }
}

【源码下载】

https://download.csdn.net/download/FL1623863129/88705587

【测试环境】

vs2019

netframework4.7.2

opencvsharp4.8.0

相关推荐
罗西的思考2 小时前
AI Agent框架探秘:拆解 OpenHands(10)--- Runtime
人工智能·算法·机器学习
冬奇Lab2 小时前
OpenClaw 源码精读(2):Channel & Routing——一条消息如何找到它的 Agent?
人工智能·开源·源码阅读
冬奇Lab2 小时前
一天一个开源项目(第38篇):Claude Code Telegram - 用 Telegram 远程用 Claude Code,随时随地聊项目
人工智能·开源·资讯
格砸4 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
可观测性用观测云4 小时前
可观测性 4.0:教系统如何思考
人工智能
sunny8654 小时前
Claude Code 跨会话上下文恢复:从 8 次纠正到 0 次的工程实践
人工智能·开源·github
小笼包包仔5 小时前
OpenClaw 多Agent软件开发最佳实践指南
人工智能
smallyoung5 小时前
AgenticRAG:智能体驱动的检索增强生成
人工智能
_skyming_5 小时前
OpenCode 如何做到结果不做自动质量评估,为什么结果还不错?
人工智能
南山安5 小时前
手写 Cursor 核心原理:从 Node.js 进程到智能 Agent
人工智能·agent·设计