C# OpenCvSharp 部署3D人脸重建3DDFA-V3
目录
说明
效果
模型信息
landmark.onnx
net_recon.onnx
net_recon_mbnet.onnx
retinaface_resnet50.onnx
项目
代码
下载
参考
C# OpenCvSharp 部署3D人脸重建3DDFA-V3
说明
地址:https://github.com/wang-zidu/3DDFA-V3
3DDFA_V3 uses the geometric guidance of facial part segmentation for face reconstruction, improving the alignment of reconstructed facial features with the original image and excelling at capturing extreme expressions. The key idea is to transform the target and prediction into semantic point sets, optimizing the distribution of point sets to ensure that the reconstructed regions and the target share the same geometry.
效果

模型信息
landmark.onnx
Model Properties
-------------------------
---------------------------------------------------------------
Inputs
-------------------------
name:input
tensor:Float[1, 3, 224, 224]
---------------------------------------------------------------
Outputs
-------------------------
name:output
tensor:Float[1, 212]
---------------------------------------------------------------
net_recon.onnx
Model Properties
-------------------------
---------------------------------------------------------------
Inputs
-------------------------
name:input
tensor:Float[1, 3, 224, 224]
---------------------------------------------------------------
Outputs
-------------------------
name:output
tensor:Float[1, 257]
---------------------------------------------------------------
net_recon_mbnet.onnx
Model Properties
-------------------------
---------------------------------------------------------------
Inputs
-------------------------
name:input
tensor:Float[1, 3, 224, 224]
---------------------------------------------------------------
Outputs
-------------------------
name:output
tensor:Float[1, 257]
---------------------------------------------------------------
retinaface_resnet50.onnx
Model Properties
-------------------------
---------------------------------------------------------------
Inputs
-------------------------
name:input
tensor:Float[1, 3, 512, 512]
---------------------------------------------------------------
Outputs
-------------------------
name:loc
tensor:Float[1, 10752, 4]
name:conf
tensor:Float[1, 10752, 2]
name:land
tensor:Float[1, 10752, 10]
---------------------------------------------------------------
项目

代码
using OpenCvSharp;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace C__OpenCvSharp_部署3D人脸重建3DDFA_V3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Stopwatch stopwatch = new Stopwatch();
Mat image;
string image_path;
string startupPath;
string model_path;
string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
const string DllName = "3DDFA_V3Sharp.dll";
IntPtr engine;
/*
//初始化
extern "C" _declspec(dllexport) int __cdecl init(void** engine, char* model_path, char* msg);
//forward
extern "C" _declspec(dllexport) int __cdecl forward(void* engine, Mat* srcimg, char* msg, Mat* render_shape, Mat* render_face, Mat* seg_face, Mat* landmarks);
//释放
extern "C" _declspec(dllexport) void __cdecl destroy(void* engine);
*/
[DllImport(DllName, EntryPoint = "init", CallingConvention = CallingConvention.Cdecl)]
internal extern static int init(ref IntPtr engine, string model_path, StringBuilder msg);
[DllImport(DllName, EntryPoint = "forward", CallingConvention = CallingConvention.Cdecl)]
internal extern static int forward(IntPtr engine, IntPtr image, StringBuilder msg, IntPtr render_shape, IntPtr render_face, IntPtr seg_face, IntPtr landmarks);
[DllImport(DllName, EntryPoint = "destroy", CallingConvention = CallingConvention.Cdecl)]
internal extern static int destroy(IntPtr engine);
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = fileFilter;
if (ofd.ShowDialog() != DialogResult.OK) return;
pictureBox1.Image = null;
pictureBox2.Image = null;
textBox1.Text = "";
image_path = ofd.FileName;
pictureBox1.Image = new Bitmap(image_path);
image = new Mat(image_path);
}
Mat render_shape;
Mat render_face;
Mat seg_face;
Mat landmarks;
private void button2_Click(object sender, EventArgs e)
{
if (image_path == "")
{
return;
}
button2.Enabled = false;
Application.DoEvents();
Cv2.DestroyAllWindows();
if (image != null) image.Dispose();
if (render_shape != null) render_shape.Dispose();
if (render_face != null) render_face.Dispose();
if (seg_face != null) seg_face.Dispose();
if (landmarks != null) landmarks.Dispose();
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
StringBuilder msg = new StringBuilder(512);
int out_imgs_size = 0;
image = new Mat(image_path);
render_shape = new Mat();
render_face = new Mat();
seg_face = new Mat();
landmarks = new Mat();
stopwatch.Restart();
int res = forward(engine, image.CvPtr, msg, render_shape.CvPtr, render_face.CvPtr, seg_face.CvPtr, landmarks.CvPtr);
if (res == 0)
{
stopwatch.Stop();
double costTime = stopwatch.Elapsed.TotalMilliseconds;
pictureBox2.Image = new Bitmap(landmarks.ToMemoryStream());
Cv2.ImShow("render_shape", render_shape);
Cv2.ImShow("render_face", render_face);
Cv2.ImShow("seg_face", seg_face);
textBox1.Text = $"耗时:{costTime:F2}ms";
}
else
{
textBox1.Text = "识别失败";
}
button2.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
startupPath = Application.StartupPath;
model_path = startupPath + "\\model\\";
StringBuilder msg = new StringBuilder(512);
int res = init(ref engine, model_path, msg);
if (res == -1)
{
MessageBox.Show(msg.ToString());
return;
}
else
{
Console.WriteLine(msg.ToString());
}
image_path = startupPath + "\\test_img\\1.jpg";
pictureBox1.Image = new Bitmap(image_path);
image = new Mat(image_path);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
destroy(engine);
}
}
}
using OpenCvSharp;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;namespace C__OpenCvSharp_部署3D人脸重建3DDFA_V3
{public partial class Form1 : Form{public Form1(){InitializeComponent();}Stopwatch stopwatch = new Stopwatch();Mat image;string image_path;string startupPath;string model_path;string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";const string DllName = "3DDFA_V3Sharp.dll";IntPtr engine;/*//初始化extern "C" _declspec(dllexport) int __cdecl init(void** engine, char* model_path, char* msg);//forwardextern "C" _declspec(dllexport) int __cdecl forward(void* engine, Mat* srcimg, char* msg, Mat* render_shape, Mat* render_face, Mat* seg_face, Mat* landmarks);//释放extern "C" _declspec(dllexport) void __cdecl destroy(void* engine);*/[DllImport(DllName, EntryPoint = "init", CallingConvention = CallingConvention.Cdecl)]internal extern static int init(ref IntPtr engine, string model_path, StringBuilder msg);[DllImport(DllName, EntryPoint = "forward", CallingConvention = CallingConvention.Cdecl)]internal extern static int forward(IntPtr engine, IntPtr image, StringBuilder msg, IntPtr render_shape, IntPtr render_face, IntPtr seg_face, IntPtr landmarks);[DllImport(DllName, EntryPoint = "destroy", CallingConvention = CallingConvention.Cdecl)]internal extern static int destroy(IntPtr engine);private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;pictureBox2.Image = null;textBox1.Text = "";image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);image = new Mat(image_path);}Mat render_shape;Mat render_face;Mat seg_face;Mat landmarks;private void button2_Click(object sender, EventArgs e){if (image_path == ""){return;}button2.Enabled = false;Application.DoEvents();Cv2.DestroyAllWindows();if (image != null) image.Dispose();if (render_shape != null) render_shape.Dispose();if (render_face != null) render_face.Dispose();if (seg_face != null) seg_face.Dispose();if (landmarks != null) landmarks.Dispose();if (pictureBox1.Image != null) pictureBox1.Image.Dispose();StringBuilder msg = new StringBuilder(512);int out_imgs_size = 0;image = new Mat(image_path);render_shape = new Mat();render_face = new Mat();seg_face = new Mat();landmarks = new Mat();stopwatch.Restart();int res = forward(engine, image.CvPtr, msg, render_shape.CvPtr, render_face.CvPtr, seg_face.CvPtr, landmarks.CvPtr);if (res == 0){stopwatch.Stop();double costTime = stopwatch.Elapsed.TotalMilliseconds;pictureBox2.Image = new Bitmap(landmarks.ToMemoryStream());Cv2.ImShow("render_shape", render_shape);Cv2.ImShow("render_face", render_face);Cv2.ImShow("seg_face", seg_face);textBox1.Text = $"耗时:{costTime:F2}ms";}else{textBox1.Text = "识别失败";}button2.Enabled = true;}private void Form1_Load(object sender, EventArgs e){startupPath = Application.StartupPath;model_path = startupPath + "\\model\\";StringBuilder msg = new StringBuilder(512);int res = init(ref engine, model_path, msg);if (res == -1){MessageBox.Show(msg.ToString());return;}else{Console.WriteLine(msg.ToString());}image_path = startupPath + "\\test_img\\1.jpg";pictureBox1.Image = new Bitmap(image_path);image = new Mat(image_path);}private void Form1_FormClosing(object sender, FormClosingEventArgs e){destroy(engine);}}
}
下载
源码下载
参考
https://github.com/hpc203/3DDFA-V3-opencv-dnn
相关文章:
C# OpenCvSharp 部署3D人脸重建3DDFA-V3
目录 说明 效果 模型信息 landmark.onnx net_recon.onnx net_recon_mbnet.onnx retinaface_resnet50.onnx 项目 代码 下载 参考 C# OpenCvSharp 部署3D人脸重建3DDFA-V3 说明 地址:https://github.com/wang-zidu/3DDFA-V3 3DDFA_V3 uses the geometri…...
【人工智能】:搭建本地AI服务——Ollama、LobeChat和Go语言的全方位实践指南
前言 随着自然语言处理(NLP)技术的快速发展,越来越多的企业和个人开发者寻求在本地环境中运行大型语言模型(LLM),以确保数据隐私和提高响应速度。Ollama 作为一个强大的本地运行框架,支持多种先…...
数据结构——堆(介绍,堆的基本操作、堆排序)
我是一个计算机专业研0的学生卡蒙Camel🐫🐫🐫(刚保研) 记录每天学习过程(主要学习Java、python、人工智能),总结知识点(内容来自:自我总结网上借鉴࿰…...
Excel中函数ABS( )的用法
Excel中函数ABS的用法 1. 函数详细讲解1.1 函数解释1.2 使用格式1.3 参数定义1.4 要点 2. 实用演示示例3. 注意事项4. 文档下载5. 其他文章6. 获取全部Excel练习素材快来试试吧🥰 函数练习素材👈点击即可进行下载操作操作注意只能下载不能在线操作 1. 函…...
【数据分析】02- A/B 测试:玩转假设检验、t 检验与卡方检验
一、背景:当“审判”成为科学 1.1 虚拟场景——法庭审判 想象这样一个场景:有一天,你在王国里担任“首席审判官”。你面前站着一位嫌疑人,有人指控他说“偷了国王珍贵的金冠”。但究竟是他干的,还是他是被冤枉的&…...
Windows下的C++内存泄漏检测工具Visual Leak Detector (VLD)介绍及使用
在软件开发过程中,内存管理是一个至关重要的环节。内存泄漏不仅会导致程序占用越来越多的内存资源,还可能引发系统性能下降甚至程序崩溃。对于Linux平台来说,内存检测工具非常丰富,GCC自带的AddressSanitizer (asan) 就是一个功能…...
[苍穹外卖] 1-项目介绍及环境搭建
项目介绍 定位:专门为餐饮企业(餐厅、饭店)定制的一款软件产品 功能架构: 管理端 - 外卖商家使用 用户端 - 点餐用户使用 技术栈: 开发环境的搭建 整体结构: 前端环境 前端工程基于 nginx 运行 - Ngi…...
人物一致性训练测评数据集
1.Pulid 训练:由1.5M张从互联网收集的高质量人类图像组成,图像标题由blip2自动生成。 测试:从互联网上收集了一个多样化的肖像测试集,该数据集涵盖了多种肤色、年龄和性别,共计120张图像,我们称之为DivID-120,作为补充资源,还使用了最近开源的测试集Unsplash-50,包含…...
AI的出现,是否能替代IT从业者?
AI的出现,是否能替代IT从业者? AI在IT领域中的应用已成趋势,IT 从业者们站在这风暴之眼,面临着一个尖锐问题:AI 是否会成为 “职业终结者”?有人担忧 AI 将取代 IT 行业的大部分工作,也有人坚信…...
乘联会:1月汽车零售预计175万辆 环比暴跌33.6%
快科技1月18日消息,据乘联会的初步推算,2025年1月狭义乘用车零售总市场规模预计将达到约175万辆左右。与去年同期相比,这一数据呈现了-14.6%的同比下降态势;而相较于上个月,则出现了-33.6%的环比暴跌情况。 为了更清晰…...
LLM - 大模型 ScallingLaws 的 CLM 和 MLM 中不同系数(PLM) 教程(2)
欢迎关注我的CSDN:https://spike.blog.csdn.net/ 本文地址:https://spike.blog.csdn.net/article/details/145188660 免责声明:本文来源于个人知识与公开资料,仅用于学术交流,欢迎讨论,不支持转载。 Scalin…...
开发神器之cursor
文章目录 cursor简介主要特点 下载cursor页面的简单介绍切换大模型指定ai学习的文件指定特定的代码喂给ai创建项目框架文件 cursor简介 Cursor 是一款专为开发者设计的智能代码编辑器,集成了先进的 AI 技术,旨在提升编程效率。以下是其主要特点和功能&a…...
使用 Ansys Motor-CAD 的自适应模板加速创新
应对现代电机设计挑战 电机设计不断发展,Ansys 正在通过创新解决方案引领潮流,不断突破可能的界限。随着电动汽车、工业自动化和可再生能源系统的快速增长,对优化电机的需求从未如此之高。工程师面临着越来越大的压力,他们需要开发…...
RabbitMQ前置概念
文章目录 1.AMQP协议是什么?2.rabbitmq端口介绍3.消息队列的作用和使用场景4.rabbitmq工作原理5.整体架构核心概念6.使用7.消费者消息推送限制(work模型)8.fanout交换机9.Direct交换机10.Topic交换机(推荐)11.声明队列…...
http转化为https生成自签名证书
背景 项目开发阶段前后交互采用http协议,演示环境采用htttps协议 ,此处为个人demo案例 组件 后端:springBoot 前端:vue web 服务:tomcat 部署环境:linux 生成自签名证书 创建目录 存储证书位置 # mkdir -p…...
《贪心算法:原理剖析与典型例题精解》
必刷的贪心算法典型例题! 算法竞赛(蓝桥杯)贪心算法1——数塔问题-CSDN博客 算法竞赛(蓝桥杯)贪心算法2——需要安排几位师傅加工零件-CSDN博客 算法(蓝桥杯)贪心算法3——二维数组排序与贪心算…...
【网络协议】【http】【https】RSA+AES-TLS1.2
【网络协议】【http】【https】RSAAES-TLS1.2 https并不是一个协议 而是在传输层之间添加了SSL/TLS协议 TLS 协议用于应用层协议(如 HTTP)和传输层(如 TCP)之间,增加了一层安全性来解决 HTTP 存在的问题,H…...
【数据库】MySQL数据库之约束与多表查询
约束 1.概述 概念:约束是作用于表中字段上的规则,用于限制存储在表中的数据目的:保证数据库中数据的正确性、有效性,完整性和一致性分类: 注意:约束是作用于表中字段上的,可以在创建表/修改表…...
【Pandas】pandas Series dot
Pandas2.2 Series Binary operator functions 方法描述Series.add()用于对两个 Series 进行逐元素加法运算Series.sub()用于对两个 Series 进行逐元素减法运算Series.mul()用于对两个 Series 进行逐元素乘法运算Series.div()用于对两个 Series 进行逐元素除法运算Series.true…...
02UML图(D2_行为图)
目录 学习前言 ---------------------------------- 讲解一:活动图 ---------------------------------- 讲解二:用例图 ---------------------------------- 讲解三:状态机图 ---------------------------------- 讲解四:…...
React 第五十五节 Router 中 useAsyncError的使用详解
前言 useAsyncError 是 React Router v6.4 引入的一个钩子,用于处理异步操作(如数据加载)中的错误。下面我将详细解释其用途并提供代码示例。 一、useAsyncError 用途 处理异步错误:捕获在 loader 或 action 中发生的异步错误替…...
synchronized 学习
学习源: https://www.bilibili.com/video/BV1aJ411V763?spm_id_from333.788.videopod.episodes&vd_source32e1c41a9370911ab06d12fbc36c4ebc 1.应用场景 不超卖,也要考虑性能问题(场景) 2.常见面试问题: sync出…...
基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真
目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销,平衡网络负载,延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...
《Playwright:微软的自动化测试工具详解》
Playwright 简介:声明内容来自网络,将内容拼接整理出来的文档 Playwright 是微软开发的自动化测试工具,支持 Chrome、Firefox、Safari 等主流浏览器,提供多语言 API(Python、JavaScript、Java、.NET)。它的特点包括&a…...
解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错
出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上,所以报错,到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本,cu、torch、cp 的版本一定要对…...
AspectJ 在 Android 中的完整使用指南
一、环境配置(Gradle 7.0 适配) 1. 项目级 build.gradle // 注意:沪江插件已停更,推荐官方兼容方案 buildscript {dependencies {classpath org.aspectj:aspectjtools:1.9.9.1 // AspectJ 工具} } 2. 模块级 build.gradle plu…...
适应性Java用于现代 API:REST、GraphQL 和事件驱动
在快速发展的软件开发领域,REST、GraphQL 和事件驱动架构等新的 API 标准对于构建可扩展、高效的系统至关重要。Java 在现代 API 方面以其在企业应用中的稳定性而闻名,不断适应这些现代范式的需求。随着不断发展的生态系统,Java 在现代 API 方…...
2.3 物理层设备
在这个视频中,我们要学习工作在物理层的两种网络设备,分别是中继器和集线器。首先来看中继器。在计算机网络中两个节点之间,需要通过物理传输媒体或者说物理传输介质进行连接。像同轴电缆、双绞线就是典型的传输介质,假设A节点要给…...
怎么开发一个网络协议模块(C语言框架)之(六) ——通用对象池总结(核心)
+---------------------------+ | operEntryTbl[] | ← 操作对象池 (对象数组) +---------------------------+ | 0 | 1 | 2 | ... | N-1 | +---------------------------+↓ 初始化时全部加入 +------------------------+ +-------------------------+ | …...
WEB3全栈开发——面试专业技能点P4数据库
一、mysql2 原生驱动及其连接机制 概念介绍 mysql2 是 Node.js 环境中广泛使用的 MySQL 客户端库,基于 mysql 库改进而来,具有更好的性能、Promise 支持、流式查询、二进制数据处理能力等。 主要特点: 支持 Promise / async-await…...
