utiliser une camera avec Aforge
Bonjour,
j'ai un soucis avec mon code.
Je voudrais afficher ma caméra, mais je n'ai rien dans ma picture box :(
j'ai mis mes id, psw et url dans des textboxs et cela fonctionne avec firefox, donc pas de soucis avec mon authentification
pas de soucis lors de la compilation...
vous auriez une piste ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| Option Strict On
Imports System.ComponentModel
Imports System.IO
Imports System.Management
Imports System.Net
Imports System.Threading
Imports AForge.Controls
Imports AForge.Video
Imports AForge.Video.DirectShow
.....
Private Sub CloseVideoSource()
If (Me.videoSourcePlayer.VideoSource IsNot Nothing) Then
Me.videoSourcePlayer.SignalToStop()
Dim num As Integer = 0
Do
Thread.Sleep(100)
num += 1
Loop While num < 30 AndAlso Me.videoSourcePlayer.IsRunning
If (Me.videoSourcePlayer.IsRunning) Then
Me.videoSourcePlayer.[Stop]()
End If
Me.videoSourcePlayer.VideoSource = Nothing
End If
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
OpenMJPEGURL()
End Sub
Private devicesCombo As New ComboBox
Private videodevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)
Public WithEvents videoSourcePlayer As New AForge.Controls.VideoSourcePlayer
Public WithEvents le_timer As New System.Windows.Forms.Timer
Private Sub OpenMJPEGURL()
Try
Dim stream As New MJPEGStream(box_url.Text)
stream.Login = box_usr.Text
stream.Password = box_psw.Text
OpenVideoSource(stream)
Catch ex As Exception
MessageBox.Show("Erreur lors de la connexion au flux vidéo : " & ex.Message)
End Try
End Sub
Private Sub OpenVideoSource(ByVal source As IVideoSource)
Try
Me.Cursor = Cursors.WaitCursor
Me.CloseVideoSource()
Me.videoSourcePlayer.VideoSource = source
Me.videoSourcePlayer.Start()
Me.le_timer.Interval = 2000
Me.le_timer.Start()
Me.Cursor = Cursors.[Default]
Catch ex As Exception
MessageBox.Show("Erreur lors de la lecture du flux vidéo : " & ex.Message)
End Try
End Sub
Private Sub Le_timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles le_timer.Tick
Dim videoSource As IVideoSource = Me.videoSourcePlayer.VideoSource
If (videoSource IsNot Nothing) Then
Dim framesReceived As Integer = videoSource.FramesReceived
PictureBox2.Image = videoSourcePlayer.GetCurrentVideoFrame
PictureBox2.Refresh()
End If
End Sub
Private Sub videoSourcePlayer_NewFrame(ByVal sender As Object, ByRef image As Bitmap) Handles videoSourcePlayer.NewFrame
PictureBox2.Image = image
End Sub |