1.根据前面文章说的添加opencvsharp程序。
2.添加代码:
VideoCapture video = new VideoCapture();
video.Open(0); //电脑默认自带摄像头为0
if (!video.IsOpened())
{
MessageBox.Show("无法打开摄像头!!!", "提示:");
}
else
{
Mat mat = new Mat();
bool bSuccess = video.Read(mat);
if (!bSuccess)
{
MessageBox.Show("无法读取摄像头的帧!!!", "提示:");
}
else
{
this.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat); //在picture控件上显示
}
}