EmguCV中的Capture类可以完成视频文件的读取,并且能捕获每一帧。
捕获的帧可绑定事件,实时对捕获的图片进行处理。
Imports Emgu Imports Emgu.CV Imports Emgu.CV.Capture Imports Emgu.CV.CvEnum Imports Emgu.CV.Structure Imports Emgu.Util Imports Emgu.CV.Util Public Class Form1 Dim _capture As Capture = Nothing Dim _captureInProgress As Boolean Private Sub initCapture() _capture = New Capture() _capture.SetCaptureProperty(CapProp.FrameWidth, 1600) _capture.SetCaptureProperty(CapProp.FrameHeight, 1200) _capture.SetCaptureProperty(CapProp.FrameCount, 1) AddHandler _capture.ImageGrabbed, AddressOf ProcessFrame '启动摄像头 switchCapture() End Sub Sub switchCapture() '启停摄像头 If Not (_capture Is Nothing) Then If (_captureInProgress) Then _capture.Pause() Else _capture.Start() End If _captureInProgress = Not _captureInProgress End If End Sub Sub ProcessFrame(sender As System.Object, e As System.EventArgs) Dim bkWhite As New Bgr(Color.White) '获得当前的图像QueryFrame() Dim frame As Image(Of Bgr, Byte) = New Image(Of Bgr, Byte)(_capture.Width, _capture.Height) _capture.Retrieve(frame) frame = frame.Rotate(270, bkWhite, False) Dim img As Image(Of Gray, Byte) = New Image(Of Gray, Byte)(frame.Width, frame.Height) frame.Convert(Of Gray, Byte).CopyTo(img) '控件实时显示摄像头捕获的视频 ImageBoxEdit.Image = frame End Sub End Class
参考文献:http://blog.csdn.net/azkabannull/article/details/7827673