C# Onnx 使用onnxruntime部署實時視頻幀插值

目錄

介紹

效果

模型信息

項目

代碼

下載


C# Onnx 使用onnxruntime部署實時視頻幀插值

介紹

github地址:https://github.com/google-research/frame-interpolation

FILM: Frame Interpolation for Large Motion, In ECCV 2022.

The official Tensorflow 2 implementation of our high quality frame interpolation neural network. We present a unified single-network approach that doesn't use additional pre-trained networks, like optical flow or depth, and yet achieve state-of-the-art results. We use a multi-scale feature extractor that shares the same convolution weights across the scales. Our model is trainable from frame triplets alone.

FILM transforms near-duplicate photos into a slow motion footage that look like it is shot with a video camera.

效果

模型信息

Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:I0
tensor:Float[1, 3, -1, -1]
name:I1
tensor:Float[1, 3, -1, -1]
---------------------------------------------------------------

Outputs
-------------------------
name:merged
tensor:Float[1, -1, -1, -1]
---------------------------------------------------------------

項目

代碼

using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Numerics;
using System.Windows.Forms;

namespace Onnx_Yolov8_Demo
{
? ? 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;
? ? ? ? string model_path;
? ? ? ? Mat image;
? ? ? ? Mat result_image;

? ? ? ? SessionOptions options;
? ? ? ? InferenceSession onnx_session;
? ? ? ? Tensor<float> input_tensor;
? ? ? ? Tensor<float> input_tensor2;
? ? ? ? List<NamedOnnxValue> input_container;
? ? ? ? IDisposableReadOnlyCollection<DisposableNamedOnnxValue> result_infer;
? ? ? ? DisposableNamedOnnxValue[] results_onnxvalue;

? ? ? ? Tensor<float> result_tensors;
? ? ? ? float[] result_array;

? ? ? ? float[] input1_image;
? ? ? ? float[] input2_image;

? ? ? ? int inpWidth;
? ? ? ? int inpHeight;

? ? ? ? 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;
? ? ? ? }

? ? ? ? void Preprocess(Mat img, ref float[] input_img)
? ? ? ? {
? ? ? ? ? ? Mat rgbimg = new Mat();
? ? ? ? ? ? Cv2.CvtColor(img, rgbimg, ColorConversionCodes.BGR2RGB);
? ? ? ? ? ? int h = rgbimg.Rows;
? ? ? ? ? ? int w = rgbimg.Cols;
? ? ? ? ? ? int align = 32;
? ? ? ? ? ? if (h % align != 0 || w % align != 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int ph = ((h - 1) / align + 1) * align;
? ? ? ? ? ? ? ? int pw = ((w - 1) / align + 1) * align;

? ? ? ? ? ? ? ? Cv2.CopyMakeBorder(rgbimg, rgbimg, 0, ph - h, 0, pw - w, BorderTypes.Constant, 0);
? ? ? ? ? ? }

? ? ? ? ? ? inpHeight = rgbimg.Rows;
? ? ? ? ? ? inpWidth = rgbimg.Cols;

? ? ? ? ? ? rgbimg.ConvertTo(rgbimg, MatType.CV_32FC3, 1 / 255.0);

? ? ? ? ? ? int image_area = rgbimg.Rows * rgbimg.Cols;

? ? ? ? ? ? //input_img = new float[3 * image_area];

? ? ? ? ? ? input_img = Common.ExtractMat(rgbimg);

? ? ? ? }

? ? ? ? Mat Interpolate(Mat srcimg1, Mat srcimg2)
? ? ? ? {
? ? ? ? ? ? int srch = srcimg1.Rows;
? ? ? ? ? ? int srcw = srcimg1.Cols;

? ? ? ? ? ? Preprocess(srcimg1, ref input1_image);
? ? ? ? ? ? Preprocess(srcimg2, ref input2_image);

? ? ? ? ? ? // 輸入Tensor
? ? ? ? ? ? input_tensor = new DenseTensor<float>(input1_image, new[] { 1, 3, inpHeight, inpWidth });
? ? ? ? ? ? input_tensor2 = new DenseTensor<float>(input2_image, new[] { 1, 3, inpHeight, inpWidth });

? ? ? ? ? ? //將tensor 放入一個輸入參數的容器,并指定名稱
? ? ? ? ? ? input_container.Add(NamedOnnxValue.CreateFromTensor("I0", input_tensor));
? ? ? ? ? ? input_container.Add(NamedOnnxValue.CreateFromTensor("I1", input_tensor2));

? ? ? ? ? ? //運行 Inference 并獲取結果
? ? ? ? ? ? result_infer = onnx_session.Run(input_container);

? ? ? ? ? ? // 將輸出結果轉為DisposableNamedOnnxValue數組
? ? ? ? ? ? results_onnxvalue = result_infer.ToArray();

? ? ? ? ? ? // 讀取第一個節點輸出并轉為Tensor數據
? ? ? ? ? ? result_tensors = results_onnxvalue[0].AsTensor<float>();

? ? ? ? ? ? int out_h = results_onnxvalue[0].AsTensor<float>().Dimensions[2];
? ? ? ? ? ? int out_w = results_onnxvalue[0].AsTensor<float>().Dimensions[3];

? ? ? ? ? ? result_array = result_tensors.ToArray();

? ? ? ? ? ? for (int i = 0; i < result_array.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result_array[i] = result_array[i] * 255;

? ? ? ? ? ? ? ? if (result_array[i] < 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? result_array[i] = 0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else if (result_array[i] > 255)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? result_array[i] = 255;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? result_array[i] = result_array[i] + 0.5f;
? ? ? ? ? ? }

? ? ? ? ? ? float[] temp_r = new float[out_h * out_w];
? ? ? ? ? ? float[] temp_g = new float[out_h * out_w];
? ? ? ? ? ? float[] temp_b = new float[out_h * out_w];

? ? ? ? ? ? Array.Copy(result_array, temp_r, out_h * out_w);
? ? ? ? ? ? Array.Copy(result_array, out_h * out_w, temp_g, 0, out_h * out_w);
? ? ? ? ? ? Array.Copy(result_array, out_h * out_w * 2, temp_b, 0, out_h * out_w);

? ? ? ? ? ? Mat rmat = new Mat(out_h, out_w, MatType.CV_32F, temp_r);
? ? ? ? ? ? Mat gmat = new Mat(out_h, out_w, MatType.CV_32F, temp_g);
? ? ? ? ? ? Mat bmat = new Mat(out_h, out_w, MatType.CV_32F, temp_b);

? ? ? ? ? ? result_image = new Mat();
? ? ? ? ? ? Cv2.Merge(new Mat[] { bmat, gmat, rmat }, result_image);

? ? ? ? ? ? result_image.ConvertTo(result_image, MatType.CV_8UC3);

? ? ? ? ? ? Mat mid_img = new Mat(result_image, new Rect(0, 0, srcw, srch));

? ? ? ? ? ? return mid_img;

? ? ? ? }

? ? ? ? private void button2_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? button2.Enabled = false;
? ? ? ? ? ? pictureBox2.Image = null;
? ? ? ? ? ? textBox1.Text = "正在運行,請稍后……";
? ? ? ? ? ? Application.DoEvents();

? ? ? ? ? ? dt1 = DateTime.Now;

? ? ? ? ? ? List<String> inputs_imgpath = new List<String>() { "test_img/frame07.png", "test_img/frame08.png", "test_img/frame09.png", "test_img/frame10.png", "test_img/frame11.png", "test_img/frame12.png", "test_img/frame13.png", "test_img/frame14.png" };

? ? ? ? ? ? int imgnum = inputs_imgpath.Count();

? ? ? ? ? ? for (int i = 0; i < imgnum - 1; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Mat srcimg1 = Cv2.ImRead(inputs_imgpath[i]);
? ? ? ? ? ? ? ? Mat srcimg2 = Cv2.ImRead(inputs_imgpath[i + 1]);

? ? ? ? ? ? ? ? Mat mid_img = Interpolate(srcimg1, srcimg2);

? ? ? ? ? ? ? ? string save_imgpath = "imgs_results/mid" + i + ".jpg";
? ? ? ? ? ? ? ? Cv2.ImWrite(save_imgpath, mid_img);
? ? ? ? ? ? }

? ? ? ? ? ? dt2 = DateTime.Now;

? ? ? ? ? ? textBox1.Text = "推理耗時:" + (dt2 - dt1).TotalMilliseconds + "ms";
? ? ? ? ? ? button2.Enabled = true;
? ? ? ? }

? ? ? ? private void Form1_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? model_path = "model/RIFE_HDv3.onnx";

? ? ? ? ? ? // 創建輸出會話,用于輸出模型讀取信息
? ? ? ? ? ? options = new SessionOptions();
? ? ? ? ? ? options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;
? ? ? ? ? ? options.AppendExecutionProvider_CPU(0);// 設置為CPU上運行

? ? ? ? ? ? // 創建推理模型類,讀取本地模型文件
? ? ? ? ? ? onnx_session = new InferenceSession(model_path, options);//model_path 為onnx模型文件的路徑

? ? ? ? ? ? // 創建輸入容器
? ? ? ? ? ? input_container = new List<NamedOnnxValue>();

? ? ? ? ? ? pictureBox1.Image = new Bitmap("test_img/frame11.png");
? ? ? ? ? ? pictureBox3.Image = new Bitmap("test_img/frame12.png");

? ? ? ? }

? ? ? ? private void pictureBox1_DoubleClick(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Common.ShowNormalImg(pictureBox1.Image);
? ? ? ? }

? ? ? ? private void pictureBox2_DoubleClick(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Common.ShowNormalImg(pictureBox2.Image);
? ? ? ? }

? ? ? ? SaveFileDialog sdf = new SaveFileDialog();
? ? ? ? private void button3_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (pictureBox2.Image == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? Bitmap output = new Bitmap(pictureBox2.Image);
? ? ? ? ? ? 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);
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? private void button4_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? button2.Enabled = false;
? ? ? ? ? ? pictureBox2.Image = null;
? ? ? ? ? ? textBox1.Text = "正在運行,請稍后……";
? ? ? ? ? ? Application.DoEvents();

? ? ? ? ? ? dt1 = DateTime.Now;

? ? ? ? ? ? Mat srcimg1 = Cv2.ImRead("test_img/frame11.png");
? ? ? ? ? ? Mat srcimg2 = Cv2.ImRead("test_img/frame12.png");

? ? ? ? ? ? Mat mid_img = Interpolate(srcimg1, srcimg2);

? ? ? ? ? ? dt2 = DateTime.Now;

? ? ? ? ? ? pictureBox2.Image = new Bitmap(mid_img.ToMemoryStream());

? ? ? ? ? ? textBox1.Text = "推理耗時:" + (dt2 - dt1).TotalMilliseconds + "ms";
? ? ? ? ? ? button2.Enabled = true;
? ? ? ? }
? ? }
}

using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Numerics;
using System.Windows.Forms;namespace Onnx_Yolov8_Demo
{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;string model_path;Mat image;Mat result_image;SessionOptions options;InferenceSession onnx_session;Tensor<float> input_tensor;Tensor<float> input_tensor2;List<NamedOnnxValue> input_container;IDisposableReadOnlyCollection<DisposableNamedOnnxValue> result_infer;DisposableNamedOnnxValue[] results_onnxvalue;Tensor<float> result_tensors;float[] result_array;float[] input1_image;float[] input2_image;int inpWidth;int inpHeight;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;}void Preprocess(Mat img, ref float[] input_img){Mat rgbimg = new Mat();Cv2.CvtColor(img, rgbimg, ColorConversionCodes.BGR2RGB);int h = rgbimg.Rows;int w = rgbimg.Cols;int align = 32;if (h % align != 0 || w % align != 0){int ph = ((h - 1) / align + 1) * align;int pw = ((w - 1) / align + 1) * align;Cv2.CopyMakeBorder(rgbimg, rgbimg, 0, ph - h, 0, pw - w, BorderTypes.Constant, 0);}inpHeight = rgbimg.Rows;inpWidth = rgbimg.Cols;rgbimg.ConvertTo(rgbimg, MatType.CV_32FC3, 1 / 255.0);int image_area = rgbimg.Rows * rgbimg.Cols;//input_img = new float[3 * image_area];input_img = Common.ExtractMat(rgbimg);}Mat Interpolate(Mat srcimg1, Mat srcimg2){int srch = srcimg1.Rows;int srcw = srcimg1.Cols;Preprocess(srcimg1, ref input1_image);Preprocess(srcimg2, ref input2_image);// 輸入Tensorinput_tensor = new DenseTensor<float>(input1_image, new[] { 1, 3, inpHeight, inpWidth });input_tensor2 = new DenseTensor<float>(input2_image, new[] { 1, 3, inpHeight, inpWidth });//將tensor 放入一個輸入參數的容器,并指定名稱input_container.Add(NamedOnnxValue.CreateFromTensor("I0", input_tensor));input_container.Add(NamedOnnxValue.CreateFromTensor("I1", input_tensor2));//運行 Inference 并獲取結果result_infer = onnx_session.Run(input_container);// 將輸出結果轉為DisposableNamedOnnxValue數組results_onnxvalue = result_infer.ToArray();// 讀取第一個節點輸出并轉為Tensor數據result_tensors = results_onnxvalue[0].AsTensor<float>();int out_h = results_onnxvalue[0].AsTensor<float>().Dimensions[2];int out_w = results_onnxvalue[0].AsTensor<float>().Dimensions[3];result_array = result_tensors.ToArray();for (int i = 0; i < result_array.Length; i++){result_array[i] = result_array[i] * 255;if (result_array[i] < 0){result_array[i] = 0;}else if (result_array[i] > 255){result_array[i] = 255;}result_array[i] = result_array[i] + 0.5f;}float[] temp_r = new float[out_h * out_w];float[] temp_g = new float[out_h * out_w];float[] temp_b = new float[out_h * out_w];Array.Copy(result_array, temp_r, out_h * out_w);Array.Copy(result_array, out_h * out_w, temp_g, 0, out_h * out_w);Array.Copy(result_array, out_h * out_w * 2, temp_b, 0, out_h * out_w);Mat rmat = new Mat(out_h, out_w, MatType.CV_32F, temp_r);Mat gmat = new Mat(out_h, out_w, MatType.CV_32F, temp_g);Mat bmat = new Mat(out_h, out_w, MatType.CV_32F, temp_b);result_image = new Mat();Cv2.Merge(new Mat[] { bmat, gmat, rmat }, result_image);result_image.ConvertTo(result_image, MatType.CV_8UC3);Mat mid_img = new Mat(result_image, new Rect(0, 0, srcw, srch));return mid_img;}private void button2_Click(object sender, EventArgs e){button2.Enabled = false;pictureBox2.Image = null;textBox1.Text = "正在運行,請稍后……";Application.DoEvents();dt1 = DateTime.Now;List<String> inputs_imgpath = new List<String>() { "test_img/frame07.png", "test_img/frame08.png", "test_img/frame09.png", "test_img/frame10.png", "test_img/frame11.png", "test_img/frame12.png", "test_img/frame13.png", "test_img/frame14.png" };int imgnum = inputs_imgpath.Count();for (int i = 0; i < imgnum - 1; i++){Mat srcimg1 = Cv2.ImRead(inputs_imgpath[i]);Mat srcimg2 = Cv2.ImRead(inputs_imgpath[i + 1]);Mat mid_img = Interpolate(srcimg1, srcimg2);string save_imgpath = "imgs_results/mid" + i + ".jpg";Cv2.ImWrite(save_imgpath, mid_img);}dt2 = DateTime.Now;textBox1.Text = "推理耗時:" + (dt2 - dt1).TotalMilliseconds + "ms";button2.Enabled = true;}private void Form1_Load(object sender, EventArgs e){model_path = "model/RIFE_HDv3.onnx";// 創建輸出會話,用于輸出模型讀取信息options = new SessionOptions();options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;options.AppendExecutionProvider_CPU(0);// 設置為CPU上運行// 創建推理模型類,讀取本地模型文件onnx_session = new InferenceSession(model_path, options);//model_path 為onnx模型文件的路徑// 創建輸入容器input_container = new List<NamedOnnxValue>();pictureBox1.Image = new Bitmap("test_img/frame11.png");pictureBox3.Image = new Bitmap("test_img/frame12.png");}private void pictureBox1_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox1.Image);}private void pictureBox2_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox2.Image);}SaveFileDialog sdf = new SaveFileDialog();private void button3_Click(object sender, EventArgs e){if (pictureBox2.Image == null){return;}Bitmap output = new Bitmap(pictureBox2.Image);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);}}private void button4_Click(object sender, EventArgs e){button2.Enabled = false;pictureBox2.Image = null;textBox1.Text = "正在運行,請稍后……";Application.DoEvents();dt1 = DateTime.Now;Mat srcimg1 = Cv2.ImRead("test_img/frame11.png");Mat srcimg2 = Cv2.ImRead("test_img/frame12.png");Mat mid_img = Interpolate(srcimg1, srcimg2);dt2 = DateTime.Now;pictureBox2.Image = new Bitmap(mid_img.ToMemoryStream());textBox1.Text = "推理耗時:" + (dt2 - dt1).TotalMilliseconds + "ms";button2.Enabled = true;}}
}

下載

源碼下載

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/696835.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/696835.shtml
英文地址,請注明出處:http://en.pswp.cn/news/696835.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

四.QT5工具安裝和環境變量的配置

1.以管理員身份運行安裝包 2.登錄qt賬號&#xff0c;點擊【next】 3.選中同意 4.選擇安裝目錄&#xff0c;注意不能有中文和空格 5.勾選 64位 mingw。點擊【next】&#xff0c;等待安裝完成 6.配置環境變量

[07] 組件注冊

目錄 Vue.js 組件局部注冊全局注冊 Vue.js 組件 組件&#xff08;Component&#xff09;是 Vue.js 最強大的功能之一。 組件可以擴展 HTML 元素&#xff0c;封裝可重用的代碼。 組件系統讓我們可以用獨立可復用的小組件來構建大型應用&#xff0c;幾乎任意類型的應用的界面都…

為什么很多人選用QT開發,有哪些應用實例?

在軟件開發領域&#xff0c;Qt框架作為一種跨平臺的C應用程序開發框架&#xff0c;近年來受到越來越多開發者的青睞。這主要得益于其卓越的跨平臺性能、豐富的功能庫、開發效率以及社區支持。以下將通過詳實的分析&#xff0c;從不同角度探討為什么很多人改用QT開發&#xff0c…

低代碼開發:學校低成本數字化轉型的新引擎

隨著科技的飛速發展&#xff0c;數字化轉型已經成為教育行業的一大趨勢。然而&#xff0c;對于許多學校來說&#xff0c;高昂的數字化改造成本成為了一道難以逾越的門檻。本文將探討如何通過低代碼開發&#xff0c;以低成本實現學校數字化轉型&#xff0c;為教育行業注入新活力…

力扣熱題100_子串_560_和為 K 的子數組

文章目錄 題目鏈接解題思路解題代碼 題目鏈接 560.和為 K 的子數組 解題思路 1.定義變量count&#xff08;計算個數&#xff0c;返回值&#xff09;為0、n&#xff08;當前nums長度&#xff09;、preSums&#xff08;利用利用defaultdict的特性&#xff0c;當presum-k不存在…

list.stream().forEach()和list.forEach()的區別

list.stream().forEach() 和 list.forEach() 在 Java 中都是用于遍歷集合元素的方法&#xff0c;但它們在使用場景和功能上有所不同&#xff1a; list.forEach()&#xff1a; 是從 Java 8 開始引入到 java.util.List 接口的標準方法。直接對列表進行迭代&#xff0c;它采用內部…

力扣645. 錯誤的集合(排序,哈希表)

Problem: 645. 錯誤的集合 文章目錄 題目描述思路復雜度Code 題目描述 思路 1.排序 1.對nums數組按從小到大的順序排序; 2.遍歷數組時若判斷兩個相鄰的元素則找到重復元素&#xff1b; 3.記錄一個整形變量prev一次置換當前位置元素并與其作差&#xff0c;若差等于2著說明缺失的…

Mysql索引操作

1、索引語法 2、慢查詢日志 慢查詢日志記錄了所有執行時間超過指定參數&#xff08; long_query_time &#xff0c;單位&#xff1a;秒&#xff0c;默認 10 秒&#xff09;的所有 SQL 語句的日志。 MySQL 的慢查詢日志默認沒有開啟&#xff0c;我們可以查看一下系統變量 slo…

MySQL數據庫備份與還原批處理腳本

數據庫備份文件&#xff0c;例如保存為&#xff1a;dump_msyql.bat REM 數據庫備份 echo offREM 激活延遲環境變量擴展&#xff0c;防止變量賦值丟失 setlocal enabledelayedexpansionREM 獲取當天時間 set today%date:~8,2%REM 大前天&#xff0c;當天-3天&#xff0c;小于10…

包裝類日期日歷類

一(Date類)&#xff1a; 在JDK的java.util包中&#xff0c;提供了Date類用于表示日期和時間&#xff0c;精確到毫秒。隨著JDK版本的不斷升級和發展&#xff0c;Date類中的大部分構造方法和普通方法都已經不推薦使用。在JDK8中&#xff0c;Date類只有2個構造方法可以使用&#x…

【LeetCode】升級打怪之路 Day 02:有序數組平方 滑動窗口法

今日題目&#xff1a; 977. 有序數組的平方 | LeetCode209. 長度最小的子數組 | LeetCode76. 最小覆蓋子串 | LeetCode59. 螺旋矩陣 II | LeetCode 目錄 今日總結Problem 1&#xff1a;有序數組平方 ???Problem 2&#xff1a;滑動窗口法 【必會】LeetCode 209. 長度最小的子…

怎樣提取WPS文檔的目錄?

怎樣提取WPS文檔的目錄&#xff08;智能識別目錄&#xff09;&#xff1f; 1. 將你的WPS文檔打開&#xff0c;菜單&#xff1a;文件&#xff1a;輸出為PDF&#xff0c;另存為(.pdf) 2. PyPDF2 從PDF文件中提取目錄 運行 python pdf_read_dir.py 你的PDF文件 或者 java : pd…

【2024軟件測試面試必會技能】Appium自動化(5):元素定位工具

常用元素定位工具使用 uiautomatorviewer定位工具&#xff1a; 元素定位主要用來獲取元素信息&#xff0c;獲取元素信息后才能用appium提供的相關API去識別和操作元素。 谷歌在AndroidSDK中&#xff0c;提供了元素定位工具uiautomatorviewer&#xff0c;該工具可在android-s…

系統學習Python——裝飾器:類裝飾器-[跟蹤對象接口:基礎知識]

分類目錄&#xff1a;《系統學習Python》總目錄 文章《系統學習Python——裝飾器&#xff1a;類裝飾器-[單例類&#xff1a;基礎知識]》的單例示例闡明了如何使用類裝飾器來管理一個類的所有實例。類裝飾器的另一個常用場景是為每個生成的實例擴展接口。類裝飾器基本上可以在實…

三opencv源碼解壓及環境變量配置

1.雙擊opencv-3.4.6-vc14-vc15.exe 2.選擇解壓的路徑&#xff0c;點擊【extract】 3.設計環境變量

從零學習Linux操作系統第二十七部分 shell腳本中的變量

一、什么是變量 變量的定義 定義本身 變量就是內存一片區域的地址 變量存在的意義 命令無法操作一直變化的目標 用一串固定的字符來表示不固定的目標可以解決此問題 二、變量的類型及命名規范 環境級別 export A1 在環境關閉后變量失效 退出后 關閉 用戶級別&#xff…

《初階數據結構》尾聲

目錄 前言&#xff1a; 《快速排序&#xff08;非遞歸&#xff09;》: 《歸并排序》&#xff1a; 《歸并排序&#xff08;非遞歸&#xff09;》&#xff1a; 《計數排序》&#xff1a; 對于快速排序的優化&#xff1a; 分析&#xff1a; 總結&#xff1a; 前言&#xff1a…

新疆營盤古城及古墓群安防艙體實施方案

3 總體布局 3.1設計原則 3.1.1執行有效的國家標準、國家軍用標準和行業標準&#xff1b; 3.1.2滿足指標要求&#xff1b; 3.1.3采用通用化、模塊化設計&#xff0c;提高設備可維修性&#xff1b; 3.1.4采用人機工程學知識進行設計&#xff0c;充分考慮安全性。 3.2 總體…

Double-DQN算法

Double-DQN算法的原理簡介、與DQN對比等。 參考深度Q網絡進階技巧 1. 原理簡介 在DQN算法中&#xff0c;雖然有target_net和eval_net&#xff0c;但還是容易出現Q值高估的情況&#xff0c;原因在于訓練時用通過target_net選取最優動作 a ? argmax ? a Q ( s t 1 , a ; w…

51單片機學習(3)-----獨立按鍵控制LED的亮滅狀態

前言&#xff1a;感謝您的關注哦&#xff0c;我會持續更新編程相關知識&#xff0c;愿您在這里有所收獲。如果有任何問題&#xff0c;歡迎溝通交流&#xff01;期待與您在學習編程的道路上共同進步了。 目錄 一. 器件介紹及實驗原理 1.獨立按鍵 &#xff08;1&#xff09;獨…