[C#]C# winform实现imagecaption图像生成描述图文描述生成

介绍:

地址:C#https://github.com/ruotianluo/ImageCaptioning.pytorch

效果:[C#]C# winform实现imagecaption图像生成描述图文描述生成_第1张图片

测试环境:

vs2019

onnxruntime1.16.3

opencvsharp4.8

代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FIRC;
using OpenCvSharp;
 
namespace imagecaptiondemo
{
    public partial class Form1 : Form
    {
        ImageCaptionManager icm = new ImageCaptionManager();
        Mat curMat = new Mat();
        public Form1()
        {
            InitializeComponent();
        }
 
        private void btn_select_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "图片文件(*.*)|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            curMat = Cv2.ImRead(ofd.FileName);
            pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(curMat);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            icm.LoadWeights();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if(pictureBox1.Image==null)
            {
                return;
            }
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var result = icm.Inference(curMat);
            sw.Stop();
            tb_res.Text = "推理耗时:" + sw.Elapsed.TotalSeconds+"秒\r\n推理结果:"+result;
 
            
        }
    }
}

视频演示:

C#实现图文描述生成imagecaption图像生成文字描述_哔哩哔哩_bilibili

源码下载地址:

https://download.csdn.net/download/FL1623863129/88681153

原文链接:https://blog.csdn.net/FL1623863129/article/details/135305444

你可能感兴趣的:(c#,开发语言)