Login Register






connect to webcam using Aforge[VB.NET] filter_list
Author
Message
connect to webcam using Aforge[VB.NET] #1
i will show you how to access into webcam using Aforge..
first of all download this if you don't have it
Aforge.controls.dll,Aforge.video.dll,Aforge.videodirectshow.dll
and add it to reference
next add :
1 button -(i named it as "button")
1 label - (i named it "label")
1 combobox - (i named it "combobox")
1 VideoSourcePlayer = ( inamed it"VideoSourcePlayer")
note : if "VideoSourcePlayer" not showing in your toolbox,right click in toolbox>choose items>under ".NET framework components click browse>navigate to your "Aforge.controls.dll" directory>click ok

next add this code:
Code:
Imports AForge.Video Imports AForge.Video.DirectShow Public Class Form1 Dim VideoCaptureSource As VideoCaptureDevice Dim VideoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim MySingleDevice As FilterInfo If VideoDevices.Count = 0 Then ComboBox.Items.Add("No Video Devices") Else For Each MySingleDevice In VideoDevices ComboBox.Items.Add(MySingleDevice.Name) Next End If ComboBox.SelectedIndex = 0 End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing VideoSourcePlayer.SignalToStop() VideoSourcePlayer.WaitForStop() VideoDevices = Nothing VideoCaptureSource = Nothing End Sub Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox.SelectedIndexChanged If ComboBox.SelectedItem <> "No Video Devices" Then If VideoSourcePlayer.IsRunning = True Then VideoSourcePlayer.SignalToStop() VideoSourcePlayer.WaitForStop() End If VideoCaptureSource = New VideoCaptureDevice(VideoDevices(ComboBox.SelectedIndex).MonikerString) VideoSourcePlayer.VideoSource = VideoCaptureSource VideoSourcePlayer.Start() End If End Sub Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click Try Dim strFilename As String strFilename = "Image-" & Format(Now, "yyyy-MMM-dd, H-mm-ss-fff") & ".jpg" If VideoSourcePlayer.IsRunning = True Then VideoSourcePlayer.GetCurrentVideoFrame.Save(System.Windows.Forms.Application.StartupPath & "\" & strFilename, System.Drawing.Imaging.ImageFormat.Jpeg) Label.Text = "Image Saved : " & strFilename End If Catch ex As Exception MessageBox.Show("Try taking snapshot again when video image is visible.", "Cannot Save Image", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub End Class

hope this things can help some one :ok:

Downlod Source code
[Image: Untitaled.png]

Reply

RE: connect to webcam using Aforge[VB.NET] #2
Thanks for the wonderful tutorial!
Good Luck!.
Visual Basic.Net

Private Message me for help

I'm not active because I'm busy with school.

Reply