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

C# GFPGAN 图像(人脸面部)修复

效果

项目

代码

using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;namespace 图像修复
{public partial class Form1 : Form{public Form1(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";string startupPath;DateTime dt1 = DateTime.Now;DateTime dt2 = DateTime.Now;int modelSize = 512;string model_path;Mat image;Mat result_image;SessionOptions options;InferenceSession onnx_session;Tensor<float> input_tensor;List<NamedOnnxValue> input_container;private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);textBox1.Text = "";image = new Mat(image_path);pictureBox2.Image = null;}private void button2_Click(object sender, EventArgs e){if (image_path == ""){return;}textBox1.Text = "";pictureBox2.Image = null;result_image = OnnxHelper.Run(image, modelSize, input_tensor, input_container, onnx_session, ref dt1, ref dt2);if (!result_image.Empty()){pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";}else{textBox1.Text = "无信息";}}private void Form1_Load(object sender, EventArgs e){startupPath = Application.StartupPath;model_path = startupPath + "\\model\\GFPGANv1.4.onnx";modelSize = 512;// 创建输出会话,用于输出模型读取信息options = new SessionOptions();options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;//设置为CPU上运行options.AppendExecutionProvider_CPU(0);// 创建推理模型类,读取本地模型文件onnx_session = new InferenceSession(model_path, options);// 输入Tensorinput_tensor = new DenseTensor<float>(new[] { 1, 3, modelSize, modelSize });// 创建输入容器input_container = new List<NamedOnnxValue>();}private void button3_Click(object sender, EventArgs e){if (pictureBox2.Image == null){return;}Bitmap output = new Bitmap(pictureBox2.Image);var sdf = new SaveFileDialog();sdf.Title = "保存";sdf.Filter = "Images (*.jpg)|*.jpg|Images (*.png)|*.png|Images (*.bmp)|*.bmp|Images (*.emf)|*.emf|Images (*.exif)|*.exif|Images (*.gif)|*.gif|Images (*.ico)|*.ico|Images (*.tiff)|*.tiff|Images (*.wmf)|*.wmf";if (sdf.ShowDialog() == DialogResult.OK){switch (sdf.FilterIndex){case 1:{output.Save(sdf.FileName, ImageFormat.Jpeg);break;}case 2:{output.Save(sdf.FileName, ImageFormat.Png);break;}case 3:{output.Save(sdf.FileName, ImageFormat.Bmp);break;}case 4:{output.Save(sdf.FileName, ImageFormat.Emf);break;}case 5:{output.Save(sdf.FileName, ImageFormat.Exif);break;}case 6:{output.Save(sdf.FileName, ImageFormat.Gif);break;}case 7:{output.Save(sdf.FileName, ImageFormat.Icon);break;}case 8:{output.Save(sdf.FileName, ImageFormat.Tiff);break;}case 9:{output.Save(sdf.FileName, ImageFormat.Wmf);break;}}MessageBox.Show("保存成功,位置:" + sdf.FileName);}}}
}

下载

可执行程序exe下载

源码下载

其他模型下载


GFPGANv1.2.onnx  

https://download.csdn.net/download/lw112190/88413009


GFPGANv1.3.onnx  

https://download.csdn.net/download/lw112190/88413007

其他

C# CodeFormer 图像修复-CSDN博客

C# RestoreFormer 图像修复-CSDN博客

C# GPEN-BFR 图像修复-CSDN博客

http://www.lryc.cn/news/197034.html

相关文章:

  • ruoyi项目登录验证变更
  • maven依赖冲突以及解决方法
  • K8S常用的一些命令及工具
  • Atlas 200I DK目标检测与追踪技术记录
  • php如何在header增加key,sign,timestamp?怎么鉴权?
  • 从代码入手理解卡尔曼滤波器的原理之使用Eigen实现二维卡尔曼滤波器(七)
  • 文件的操作
  • left join时筛选条件对查询结果的
  • CVE-2020-9483 apache skywalking SQL注入漏洞
  • PaddleX解决分类、检测两大场景问题?实战精讲教程来了!
  • Hive用户中文使用手册系列(二)
  • 2023年中国清净剂行业需求现状及前景分析[图]
  • 文心一言 VS 讯飞星火 VS chatgpt (115)-- 算法导论10.2 8题
  • Redis的BitMap实现分布式布隆过滤器
  • 【linux API分析】module_init
  • NSDT孪生编辑器助力智慧城市
  • 如何优雅的实现接口统一调用
  • tomcat、nginx实现四层转发+七层代理+动静分离实验
  • 交通目标检测-行人车辆检测流量计数 - 计算机竞赛
  • Java Excel转PDF,支持xlsx和xls两种格式, itextpdf【即取即用】
  • 重生奇迹mu宠物带来不一样的体验
  • 【C++笔记】多态的原理、单继承和多继承关系的虚函数表、 override 和 final、抽象类、重载、覆盖(重写)、隐藏(重定义)的对比
  • 安装thinkphp6并使用多应用模式,解决提示路由不存在解决办法
  • FPGA笔试
  • Pytorch:cat、stack、squeeze、unsqueeze的用法
  • 聊聊HttpClient的RedirectStrategy
  • 【1day】复现宏景OA KhFieldTree接口 SQL注入漏洞
  • 同为科技TOWE智能PDU引领数据中心机房远控用电安全高效
  • 支付成功后给指定人员发送微信公众号消息
  • 漏洞复现--安恒明御安全网关文件上传