我正在使用 EMGU.CV 在 VB.NET 中处理多个网络摄像头,专门用于实时录制视频。
问题是,当相机被拔掉或突然发生故障时,我需要PictureBox
包含图像捕获来只显示任何内容。
我正在使用以下代码:
Try
'===================== CAM 1
imagez0 = Capturez0.RetrieveBgrFrame
PictureBox1.BackgroundImage = imagez0.ToBitmap()
Videoz.WriteFrame(imagez0)
drawbitmap1 = New Bitmap(PictureBox1.Width, PictureBox1.Height)
graph = Graphics.FromImage(drawbitmap1)
graph.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
graph.DrawString(x + " | CAM 1 | Faculty", Label1.Font, brush, PictureBox1.Location)
PictureBox1.Image = drawbitmap1
Catch ex As Exception
Capturez0.Stop()
imagez0 = Nothing
Videoz.WriteFrame(imagez0)
PictureBox1.Image = Nothing
PictureBox1.BackgroundImage = Nothing
Videoz = Nothing
End Try
但是当我尝试拔下网络摄像头时,它只挂在它捕获的最后一张图像上,然后什么也不做,只是挂在那个图像上。我认为代码不属于Catch exception
这就是图像仍然可用的原因。
然后,当我尝试将相机放回原处时,它不会继续录制。它就在那里卡住了。