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

C# RestoreFormer 图像修复

效果

项目

代码

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\\restoreformer.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下载

源码下载

其他

C# CodeFormer 图像修复-CSDN博客

C# Onnx GFPGAN GPEN-BFR 人像修复-CSDN博客

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

相关文章:

  • yolov5+车辆重识别【附代码】
  • C语言练习百题之#ifdef和#ifndef的应用
  • 与C语言不同的基础语法
  • Python文件读写实战:处理日常任务的终极工具!
  • 思维模型 秩序
  • pyqt5移动鼠标时显示鼠标坐标
  • 分享一下开发回收废品小程序的步骤
  • 568A和568B两种线序
  • kafka广播消费组停机后未删除优化
  • 深度学习自学笔记十三:unet网络详解和环境配置
  • 如何给苹果ipa和安卓apk应用APP包体修改手机屏幕上logo图标iocn?
  • 复旦MBA魏文童:构建完备管理知识体系,助力企业数字化发展
  • 【算能】在Docker中调用PCIe卡
  • 【MySQL】表的查询与连接
  • AtCoder Beginner Contest 324(F)
  • LuatOS-SOC接口文档(air780E)-- i2s - 数字音频
  • 瑞芯微RK3568核心板在边缘服务器产品中的应用-迅为电子
  • pg ash自制版 pg_active_session_history
  • Elasticsearch系列组件:Kibana无缝集成的数据可视化和探索平台
  • phpcms_v9模板制作及二次开发常用代码
  • 自然语言处理(NLP)-概述
  • Python开发者的宝典:CSV和JSON数据处理技巧大公开!
  • Unity中Commpont类获取子物体的示例
  • 【Vue面试题二十一】、Vue中的过滤器了解吗?过滤器的应用场景有哪些?
  • Unity 3D基础——缓动效果
  • 高校教务系统登录页面JS分析——南京邮电大学
  • css实现排行榜样式(vue组件)
  • I2VGen-XL高清图像生成视频大模型
  • Angular知识点系列(1)-每天10个小知识
  • 【从0开发】百度BML全功能AI开发平台【实操:以部署情感分析模型为例】