[C#]C# winform实现imagecaption图像生成描述图文描述生成
2023-12-30 19:17:48
介绍:
地址:C#https://github.com/ruotianluo/ImageCaptioning.pytorch
效果:
测试环境:
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;
}
}
}
?视频演示:
源码下载地址:
文章来源:https://blog.csdn.net/FL1623863129/article/details/135305444
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!