Захват одного кадра с помощью directshow in VB.NET
Привет
У меня есть какой-то код для захвата видео с веб-камеры. Как я мог бы захватить кадр из него в растровом формате?
Enum PlayState init stopped paused running End Enum Dim currentState As PlayState = PlayState.stopped Dim d As Integer = Convert.ToInt32("0X8000", 16) Dim WM_GRAPHNOTIFY As Integer = d + 1 Dim videoWindow As IVideoWindow = Nothing Dim mediaControl As IMediaControl = Nothing Dim mediaEventEx As IMediaEventEx = Nothing Dim graphBuilder As IGraphBuilder = Nothing Dim captureGraphBuilder As ICaptureGraphBuilder2 = Nothing Dim rot As DsROTEntry = Nothing Private Sub startPreview() Dim sourceFilter As IBaseFilter = Nothing graphBuilder = CType(New FilterGraph, IGraphBuilder) captureGraphBuilder = CType(New CaptureGraphBuilder2, ICaptureGraphBuilder2) mediaControl = CType(graphBuilder, IMediaControl) videoWindow = CType(graphBuilder, IVideoWindow) mediaEventEx = CType(graphBuilder, IMediaEventEx) mediaEventEx.SetNotifyWindow(Me.Handle, WM_GRAPHNOTIFY, IntPtr.Zero) captureGraphBuilder.SetFiltergraph(graphBuilder) sampGrabber = CType(New SampleGrabber, ISampleGrabber) baseGrabFlt = CType(sampGrabber, IBaseFilter) Dim classEnum As IEnumMoniker = Nothing Dim moniker As IMoniker() = New IMoniker(0) {} Dim source As Object = Nothing Dim devEnum As ICreateDevEnum = CType(New CreateDevEnum, ICreateDevEnum) devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, classEnum, 0) Marshal.ReleaseComObject(devEnum) If classEnum Is Nothing Then Throw New ApplicationException("No camera detected") If classEnum.Next(moniker.Length, moniker, IntPtr.Zero) = 0 Then moniker(0).BindToObject(Nothing, Nothing, GetType(IBaseFilter).GUID, source) Else Throw New ApplicationException("Detected camera is inaccessible") End If Marshal.ReleaseComObject(moniker(0)) Marshal.ReleaseComObject(classEnum) sourceFilter = CType(source, IBaseFilter) graphBuilder.AddFilter(sourceFilter, "Video Capture") captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, Nothing, Nothing) Marshal.ReleaseComObject(sourceFilter) videoWindow.put_Owner(CAM1.Handle) videoWindow.put_WindowStyle(WindowStyle.Child Or WindowStyle.ClipChildren) videoWindow.SetWindowPosition(0, 0, CAM1.Width, CAM1.Height) videoWindow.put_Visible(OABool.True) rot = New DsROTEntry(graphBuilder) mediaControl.Run() currentState = PlayState.running CAM1Online = True End Sub
Что я уже пробовал:
Попробовал заглянуть в ISampleGrabber, но в VB ничего нет.
MCSIDevelopers
Вы имеете в виду захват изображения?
Member 11450536
Да, с предварительного просмотра веб-камеры