Skip to content

Instantly share code, notes, and snippets.

@GTHell
Created November 21, 2018 04:12
Show Gist options
  • Select an option

  • Save GTHell/e9f43618ce4835e89e6b3f9067293f4c to your computer and use it in GitHub Desktop.

Select an option

Save GTHell/e9f43618ce4835e89e6b3f9067293f4c to your computer and use it in GitHub Desktop.
c#
https://stackoverflow.com/questions/49300510/visual-studio-c-sharp-videocapture
public partial class Form1 : Form
{
VideoCapture _capture;
private Mat _frame;
private void ProcessFrame(object sender, EventArgs e)
{
if (_capture != null && _capture.Ptr != IntPtr.Zero)
{
_capture.Retrieve(_frame, 0);
pictureBox1.Image = _frame.Bitmap;
}
}
public Form1()
{
InitializeComponent();
_capture = new VideoCapture(0);
_capture.ImageGrabbed += ProcessFrame;
_frame = new Mat();
if (_capture != null)
{
try
{
_capture.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment