本人在网上参考人家的写法:
private void button1_Click(object sender, EventArgs e) { Capture capture = new Capture("d:\1.mp4"); while (true) { Image<Bgr, Byte> frame = capture.QueryFrame(); if (frame != null) { Image<Gray,byte> grayFrame = frame.Convert<Gray,byte>(); grayFrame.Resize(this.Width,this.Height,INTER.CV_INTER_CUBIC); this.imageBox1.Image = grayFrame; // RefreshPictureBoxDelegate fresh = this.RefreshPictureBox; //this.BeginInvoke(fresh,grayFrame.ToBitmap()); //imageBox1.Image = frame; } //Thread.Sleep(500); } } public delegate void RefreshPictureBoxDelegate(Bitmap frame); private void RefreshPictureBox(Bitmap frame) { this.pictureBox1.Image = frame; //this.imageBox1.Image = frame; }
解决方案
30
public partial class Form1 : Form { Capture _capture; public Form1() { InitializeComponent(); _capture = new Capture(); _capture.ImageGrabbed += _capture_ImageGrabbed; _capture.Start(); } void _capture_ImageGrabbed(object sender, EventArgs e) { var frame = _capture.RetrieveBgrFrame(); pic.Image = frame.Bitmap; } }