当前位置: 首页 > news >正文

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、人工智能),总结知识点(内容来自:自我总结网上借鉴&#xff0…...

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_行为图)

目录 学习前言 ---------------------------------- 讲解一:活动图 ---------------------------------- 讲解二:用例图 ---------------------------------- 讲解三:状态机图 ---------------------------------- 讲解四&#xff1a…...

AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南

点一下关注吧!!!非常感谢!!持续更新!!! 🚀 AI篇持续更新中!(长期更新) 目前2025年06月05日更新到: AI炼丹日志-28 - Aud…...

微信小程序之bind和catch

这两个呢,都是绑定事件用的,具体使用有些小区别。 官方文档: 事件冒泡处理不同 bind:绑定的事件会向上冒泡,即触发当前组件的事件后,还会继续触发父组件的相同事件。例如,有一个子视图绑定了b…...

React hook之useRef

React useRef 详解 useRef 是 React 提供的一个 Hook,用于在函数组件中创建可变的引用对象。它在 React 开发中有多种重要用途,下面我将全面详细地介绍它的特性和用法。 基本概念 1. 创建 ref const refContainer useRef(initialValue);initialValu…...

Unity3D中Gfx.WaitForPresent优化方案

前言 在Unity中,Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染(即CPU被阻塞),这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案: 对惹,这里有一个游戏开发交流小组&…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日,中天合创屋面分布式光伏发电项目顺利并网发电,该项目位于内蒙古自治区鄂尔多斯市乌审旗,项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站,总装机容量为9.96MWp。 项目投运后,每年可节约标煤3670…...

Spring Boot+Neo4j知识图谱实战:3步搭建智能关系网络!

一、引言 在数据驱动的背景下,知识图谱凭借其高效的信息组织能力,正逐步成为各行业应用的关键技术。本文聚焦 Spring Boot与Neo4j图数据库的技术结合,探讨知识图谱开发的实现细节,帮助读者掌握该技术栈在实际项目中的落地方法。 …...

实现弹窗随键盘上移居中

实现弹窗随键盘上移的核心思路 在Android中&#xff0c;可以通过监听键盘的显示和隐藏事件&#xff0c;动态调整弹窗的位置。关键点在于获取键盘高度&#xff0c;并计算剩余屏幕空间以重新定位弹窗。 // 在Activity或Fragment中设置键盘监听 val rootView findViewById<V…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台

🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...

C++使用 new 来创建动态数组

问题&#xff1a; 不能使用变量定义数组大小 原因&#xff1a; 这是因为数组在内存中是连续存储的&#xff0c;编译器需要在编译阶段就确定数组的大小&#xff0c;以便正确地分配内存空间。如果允许使用变量来定义数组的大小&#xff0c;那么编译器就无法在编译时确定数组的大…...

LLMs 系列实操科普(1)

写在前面&#xff1a; 本期内容我们继续 Andrej Karpathy 的《How I use LLMs》讲座内容&#xff0c;原视频时长 ~130 分钟&#xff0c;以实操演示主流的一些 LLMs 的使用&#xff0c;由于涉及到实操&#xff0c;实际上并不适合以文字整理&#xff0c;但还是决定尽量整理一份笔…...