using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;
// Important: include the opencvsharp library in your code
using OpenCvSharp;
using OpenCvSharp.Extensions;
namespace CameraApp
{
public partial class Form1 : Form
{
private Thread camera;
private void CaptureCamera()
{
camera = new Thread(new ThreadStart(CaptureCameraCallback));
camera.Start();
}
private void CaptureCameraCallback()
{
VideoCapture capture = new VideoCapture(0);
capture.Open(0);
while (true)
{
pictureBox1.Image = BitmapConverter.ToBitmap(capture.RetrieveMat());
}
}
public Form1()
{
InitializeComponent();
CaptureCamera();
}
// When the user clicks on the start/stop button, start or release the camera and setup flags
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Show();
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Hide();
}
}
}
pictureBox1.Image = BitmapConverter.ToBitmap(capture.RetrieveMat());