介绍:
github地址:https://github.com/derronqi/yolov8-face
效果:
![[C#]OpenCvSharp实现Yolov8 Face Landmarks 人脸关键点检测_System](https://file.cfanz.cn/uploads/jpeg/2024/10/12/0/e543VQ5104.jpeg)
项目:
![[C#]OpenCvSharp实现Yolov8 Face Landmarks 人脸关键点检测_Image_02](https://file.cfanz.cn/uploads/jpeg/2024/10/12/0/fH2535GALP.jpeg)
代码:
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 results = fd.Inference(src);
var resultMat = fd.DrawImage(src,results);
pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap
}
private void Form1_Load(object sender, EventArgs e)
{
fd.LoadWeights(Application.StartupPath+"\\weights\\yolov8n-face.onnx");
}
private void btn_video_Click(object sender, EventArgs e)
{
}
}
}测试环境:
vs2019
net framework4.7.2
opencvsharp4.8









