Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Collections.Generic
- Imports System.ComponentModel
- Imports System.Data
- Imports System.Drawing
- Imports System.Text
- Imports System.Windows.Forms
- Imports AForge.Video
- Imports AForge.Video.DirectShow
- Public Class Form1
- Dim VideoCaptureSource As VideoCaptureDevice
- 'Dim VideoCaptureSource2 As VideoCaptureDevice
- Dim VideoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)
- 'Dim VideoDevices2 As New FilterInfoCollection(FilterCategory.VideoInputDevice)
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Try
- Timer1.Interval = 80
- Timer1.Enabled = False
- If VideoSourcePlayer1.IsRunning = True Then
- VideoSourcePlayer1.GetCurrentVideoFrame()
- End If
- If VideoSourcePlayer2.IsRunning = True Then
- VideoSourcePlayer2.GetCurrentVideoFrame()
- End If
- Catch ex As Exception
- End Try
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Try
- ' enumerate video devices
- If VideoDevices.Count = 0 Then
- ComboBox1.Items.Add("No Video Devices")
- End If
- Dim i As Integer = 1, n As Integer = VideoDevices.Count
- While i <= n
- Dim cameraName As String = i + " : " + VideoDevices(i - 1).Name
- ComboBox1.Items.Add(cameraName)
- ComboBox2.Items.Add(cameraName)
- System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
- End While
- ' check cameras count
- If VideoDevices.Count = 1 Then
- ComboBox2.Items.Clear()
- ComboBox2.Items.Add("Only one camera found")
- ComboBox2.SelectedIndex = 0
- ComboBox2.Enabled = False
- Else
- ComboBox2.SelectedIndex = 1
- End If
- ComboBox1.SelectedIndex = 0
- Catch
- Button2.Enabled = False
- ComboBox1.Items.Add("No cameras found")
- ComboBox2.Items.Add("No cameras found")
- ComboBox1.SelectedIndex = 0
- ComboBox2.SelectedIndex = 0
- ComboBox1.Enabled = True
- ComboBox2.Enabled = True
- End Try
- End Sub
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- StopCameras()
- End Sub
- Sub StartCameras()
- ' create first video source
- Dim videoSource1 As New VideoCaptureDevice(VideoDevices(ComboBox1.SelectedIndex).MonikerString)
- VideoSourcePlayer1.VideoSource = videoSource1
- VideoSourcePlayer1.Start()
- ' create second video source
- If ComboBox2.Enabled = True Then
- System.Threading.Thread.Sleep(500)
- Dim videoSource2 As New VideoCaptureDevice(VideoDevices(ComboBox2.SelectedIndex).MonikerString)
- VideoSourcePlayer2.VideoSource = videoSource2
- VideoSourcePlayer2.Start()
- End If
- ' start timer
- Timer1.Start()
- End Sub
- Sub StopCameras()
- VideoSourcePlayer1.SignalToStop()
- VideoSourcePlayer2.SignalToStop()
- VideoSourcePlayer1.WaitForStop()
- VideoSourcePlayer2.WaitForStop()
- VideoDevices = Nothing
- VideoCaptureSource = Nothing
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- StartCameras()
- Button1.Enabled = False
- Button2.Enabled = True
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- StopCameras()
- Button1.Enabled = True
- Button2.Enabled = False
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement