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.pswp.cn/web/66420.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/66420.shtml
英文地址,請注明出處:http://en.pswp.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)以及排序(這里采用一種簡單的排序方法,例如冒泡排序)的操作示…