C# InformativeDrawings 生成素描画
  yqdtHKhvd9Ja 2023年12月15日 35 0


目录

效果

模型信息

anime_style_512x512.onnx

contour_style_512x512.onnx

opensketch_style_512x512.onnx

项目

代码

创建Tensor

保存

下载


效果

C# InformativeDrawings 生成素描画_C#  生成素描画

C# InformativeDrawings 生成素描画_c#_02

C# InformativeDrawings 生成素描画_机器学习_03

C# InformativeDrawings 生成素描画_c#_04

C# InformativeDrawings 生成素描画_c#_05

C# InformativeDrawings 生成素描画_人工智能_06

模型信息

anime_style_512x512.onnx

Inputs
-------------------------
name:input_image
tensor:Float[1, 3, 512, 512]
---------------------------------------------------------------

Outputs
-------------------------
name:output_image
tensor:Float[1, 1, 512, 512]
---------------------------------------------------------------

contour_style_512x512.onnx

Inputs
-------------------------
name:input_image
tensor:Float[1, 3, 512, 512]
---------------------------------------------------------------

Outputs
-------------------------
name:output_image
tensor:Float[1, 1, 512, 512]
---------------------------------------------------------------

opensketch_style_512x512.onnx

Inputs
-------------------------
name:input_image
tensor:Float[1, 3, 512, 512]
---------------------------------------------------------------

Outputs
-------------------------
name:output_image
tensor:Float[1, 1, 512, 512]
---------------------------------------------------------------

项目

VS2022

.net framework 4.8

OpenCvSharp 4.8

Microsoft.ML.OnnxRuntime 1.16.2

C# InformativeDrawings 生成素描画_c#_07

代码

创建Tensor

input_tensor = new DenseTensor<float>(new[] { 1, 3, modelSize, modelSize });
for (int y = 0; y < resize_image.Height; y++)
 {
     for (int x = 0; x < resize_image.Width; x++)
     {
         input_tensor[0, 0, y, x] = resize_image.At<Vec3b>(y, x)[0];
         input_tensor[0, 1, y, x] = resize_image.At<Vec3b>(y, x)[1];
         input_tensor[0, 2, y, x] = resize_image.At<Vec3b>(y, x)[2];
     }
 }

保存

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下载

源码下载


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月15日 0

暂无评论

推荐阅读
yqdtHKhvd9Ja