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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/66420.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

从零开始学数据库 day2 DML

从零开始学数据库:DML操作详解 在今天的数字化时代,数据库的使用已经成为了各行各业的必备技能。无论你是想开发一个简单的应用,还是想要管理复杂的数据,掌握数据库的基本操作都是至关重要的。在这篇博客中,我们将专注…

Java 8 Stream API

文章目录 Java 8 Stream API1. Stream2. Stream 的创建3. 常见的 Stream 操作3.1 中间操作3.2 终止操作 4. Stream 的并行操作 Java 8 Stream API Java 8 引入了 Stream API,使得对集合类(如 List、Set 等)的操作变得更加简洁和直观。Stream…

运行fastGPT 第五步 配置FastGPT和上传知识库 打造AI客服

运行fastGPT 第五步 配置FastGPT和上传知识库 打造AI客服 根据上一步的步骤,已经调试了ONE API的接口,下面,我们就登陆fastGPT吧 http://xxx.xxx.xxx.xxx:3000/ 这个就是你的fastGPT后台地址,可以在configer文件中找到。 账号是…

第4章 Kafka核心API——Kafka客户端操作

Kafka客户端操作 一. 客户端操作1. AdminClient API 一. 客户端操作 1. AdminClient API

【王树森搜索引擎技术】相关性02:评价指标(AUC、正逆序比、DCG)

相关性的评价指标 Pointwise评价指标:Area Under the Curve(AUC)Pairwise评价指标:正逆序比(Positive to Negative Ratio, PNR)Listwise评价指标:Discounted Cumulative Gain(DCG)用AUC和PNR作…

人物一致性训练测评数据集

1.Pulid 训练:由1.5M张从互联网收集的高质量人类图像组成,图像标题由blip2自动生成。 测试:从互联网上收集了一个多样化的肖像测试集,该数据集涵盖了多种肤色、年龄和性别,共计120张图像,我们称之为DivID-120,作为补充资源,还使用了最近开源的测试集Unsplash-50,包含…

Android 项目依赖冲突问题:Duplicate class found in modules

问题描述与处理处理 1、问题描述 plugins {id com.android.application }android {compileSdk 34defaultConfig {applicationId "com.my.dialog"minSdk 21targetSdk 34versionCode 1versionName "1.0"testInstrumentationRunner "androidx.test.run…

计算机网络 | 什么是公网、私网、NAT?

关注:CodingTechWork 引言 计算机网络是现代信息社会的基石,而网络通信的顺畅性和安全性依赖于有效的IP地址管理和网络转换机制。在网络中,IP地址起到了标识设备和进行数据传输的核心作用。本文将详细讨论公网IP、私网IP以及NAT转换等网络技…

python+django+Nacos实现配置动态更新-集中管理配置(实现mysql配置动态读取及动态更新)

一、docker-compose.yml 部署nacos服务 version: "3" services:mysql:container_name: mysql# 5.7image: mysql:5.7environment:# mysql root用户密码MYSQL_ROOT_PASSWORD: rootTZ: Asia/Shanghai# 初始化数据库(后续的初始化sql会在这个库执行)MYSQL_DATABASE: nac…

深度学习项目--基于LSTM的火灾预测研究(pytorch实现)

🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍖 原作者:K同学啊 前言 LSTM模型一直是一个很经典的模型,这个模型当然也很复杂,一般需要先学习RNN、GRU模型之后再学,GRU、LSTM的模型讲解将…

基于 WEB 开发的汽车养护系统设计与实现

标题:基于 WEB 开发的汽车养护系统设计与实现 内容:1.摘要 本文介绍了基于 WEB 开发的汽车养护系统的设计与实现。文章首先阐述了系统的背景和目的,即随着汽车保有量的增加,汽车养护需求日益增长,传统的汽车养护方式已经无法满足人们的需求&…

GitLab集成Jira

GitLab与Jira集成的两种方式 GitLab 提供了两种 Jira 集成,即Jira议题集成和Jira开发面板集成,可以配置一个或者两个都配置。 具体集成步骤可以参考官方文档Jira 议题集成(极狐GitLab文档)和Jira 开发面板集成(极狐G…

【爬虫】某某查cookie逆向

代码仅供技术人员进行学习和研究使用,请勿将其用于非法用途或以任何方式窃取第三方数据。使用该代码产生的所有风险均由用户自行承担,作者不对用户因使用该代码而造成的任何损失或损害承担任何责任。 加密参数 加密参数主要是cookie,其中只有…

A5.Springboot-LLama3.2服务自动化构建(二)——Jenkins流水线构建配置初始化设置

下面我们接着上一篇文章《A4.Springboot-LLama3.2服务自动化构建(一)——构建docker镜像配置》继续往下分析,在自动化流水线构建过程当中的相关初始化设置和脚本编写。 一、首先需要先安装Jenkins 主部分请参考我前面写的一篇文章《Jenkins持续集成与交付安装配置》 二、…

如何设置HTTPS站点防御?

设置HTTPS站点防御涉及到多个层面的安全措施,包括但不限于配置Web服务器、应用安全头信息、使用内容安全策略(CSP)、启用HSTS和OCSP Stapling等。下面是一些关键的步骤来增强HTTPS网站的安全性: 1. 使用强加密协议和密钥交换算法…

[Java]类和对象

1. 什么是类? 类(Class)是蓝图或者模板。它定义了对象的属性和行为。 类就是一种抽象的模板,你可以通过它创建多个对象。类定义了对象的属性(变量)和行为(方法)。我们可以把类理解…

win32汇编环境,窗口程序中基础列表框的应用举例

;运行效果 ;win32汇编环境,窗口程序中基础列表框的应用举例 ;比如在窗口程序中生成列表框,增加子项,删除某项,取得指定项内容等 ;直接抄进RadAsm可编译运行。重点部分加备注。 ;以下是ASM文件 ;>>>>>>>>>>>…

【机器学习实战入门】使用LSTM机器学习预测股票价格

机器学习在股票价格预测中有重要的应用。在这个机器学习项目中,我们将讨论如何预测股票的收益。这是一个非常复杂的任务,充满了不确定性。我们将会把这个项目分成两部分进行开发: 首先,我们将学习如何使用 LSTM 神经网络预测股票…

【编程语言】C/C++语言常见标准和规范

C/C 是两种功能强大且广泛使用的编程语言。尽管它们没有像 Java 那样强制性的命名规则,但为了提高代码的可读性和可维护性,遵循一些普遍认同的编程规范和标准仍然是非常重要的。本文将探讨 C/C 编程中的一些命名规范及标准,以帮助开发者编写更…

使用C语言实现栈的插入、删除和排序操作

栈是一种后进先出(LIFO, Last In First Out)的数据结构,这意味着最后插入的元素最先被删除。在C语言中,我们可以通过数组或链表来实现栈。本文将使用数组来实现一个简单的栈,并提供插入(push)、删除(pop)以及排序(这里采用一种简单的排序方法,例如冒泡排序)的操作示…