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

C# CodeFormer 图像修复

效果

项目

代码 

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\\codeformer.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# GFPGAN 图像修复-CSDN博客

C# RestoreFormer 图像修复-CSDN博客

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

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

相关文章:

  • Android Studio的笔记--HttpURLConnection使用GET下载zip文件
  • phantom3D模体
  • 贪心算法解决批量开票限额的问题
  • Unity后台登录/获取数据——BestHTTP的使用Get/Post
  • 【Windows日志】记录系统事件的日志
  • 物联网开发学习笔记——目录索引
  • Prometheus:优秀和强大的监控报警工具
  • Appium
  • 自动驾驶学习笔记(五)——绕行距离调试
  • 【Android】VirtualDisplay创建流程及原理
  • Linux服务器快速搭建pytorch
  • 声音克隆,定制自己的声音,使用最新版Bert-VITS2的云端训练+推理记录
  • LeetCode讲解篇之198. 打家劫舍
  • 【下载共享文件】Java基于SMB协议 + JCIFS依赖下载Windows共享文件(亲测可用)
  • 【评分卡实现】应用Python中的toad.ScoreCard函数实现评分卡
  • 【数据结构】双链表的相关操作(声明结构体成员、初始化、判空、增、删、查)
  • 解析找不到msvcp140.dll的5个解决方法,快速修复dll丢失问题
  • 代码管理工具 gitlab实战应用
  • 小谈设计模式(27)—享元模式
  • 网络代理技术:隐私保护与安全加固的利器
  • orgChart.js组织架构图
  • 华纳云:SQL Server怎么批量导入和导出数据
  • 深入了解桶排序:原理、性能分析与 Java 实现
  • 微店店铺所有商品数据接口,微店整店商品数据接口,微店店铺商品数据接口,微店API接口
  • SSL证书能选择免费的吗?
  • 苹果macOS电脑版 植物大战僵尸游戏
  • 【每日一题】ABC311G - One More Grid Task | 单调栈 | 简单
  • 第五十六章 学习常用技能 - 执行 SQL 查询
  • 2023年起重信号司索工(建筑特殊工种)证考试题库及起重信号司索工(建筑特殊工种)试题解析
  • 《华为战略管理法:DSTE实战体系》作者谢宁老师受邀为某电力上市集团提供两天的《成功的产品管理及产品经理》内训。