C# winform控件+EmguCv 打开指定视频文件并在ImageBox中进行播放展示

本文参考:浅入浅出EmguCv(三)EmguCv打开指定视频
打开视频的思路跟打开图片的思路是一样的,只不过视频是由一帧帧图片组成,因此,打开视频的处理程序有一个连续的获取图片并逐帧显示的处理过程
一.控件
在面板中拖入一个button和一个ImageBox(注意ImageBox控件为EmguCv控件)
在这里插入图片描述
二.代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.UI;
using Emgu.CV.ML;


namespace EMGUCVtest
{
    public partial class CameraCapture : Form
    {
        //declaring global variables
        private VideoCapture capture;
        private bool isProcess = false;
     
      
        public CameraCapture()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dilog = new OpenFileDialog();

            if (dilog.ShowDialog() == DialogResult.OK || dilog.ShowDialog() == DialogResult.Yes)
            {
                ImageViewer viewer = new ImageViewer();
                VideoCapture capture = new VideoCapture(dilog.FileName);

                Application.Idle += new EventHandler(delegate (object sendero, EventArgs eo)
                {
                    Mat frame = capture.QueryFrame();
                    System.Threading.Thread.Sleep(1);
                    imageBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    imageBox1.Image = frame;
                });
            }
        }
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值