目录
效果
模型信息
anime_style_512x512.onnx
contour_style_512x512.onnx
opensketch_style_512x512.onnx
项目
代码
创建Tensor
保存
下载
效果
模型信息
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
代码
创建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下载
源码下载