Sorry, nochmal WebCam

  • .NET (FX) 4.5–4.8
  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Morrison.

    Sorry, nochmal WebCam

    Hallo,

    ich habe nun so gut, wie jeden Beitrag über WebCams in vb durchgelesen und mir unzählige Beispiele heruntergeladen. Leider war da keines dabei, welches bei mir fehlerfrei funktioniert hat. Entweder stürzt das Programm ab, oder es erscheint keine Fehlermeldung und auch kein Bild. Folgendes Beispiel habe ich als Letztes getestet:

    VB.NET-Quellcode

    1. Imports System.IO
    2. Public Class Form1
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. 'Video starten'
    5. videoHandle = Me.CreateCaptureWindow(Picturebox1.Handle)
    6. 'video ende^^
    7. End Sub
    8. Dim videoHandle As IntPtr
    9. Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    10. Declare Auto Function capCreateCaptureWindow Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Short, ByVal y As Integer, ByVal nWidth As Short, ByVal nHeight As Short, ByVal hWndParent As IntPtr, ByVal nID As Byte) As IntPtr
    11. Const EM_LINEFROMCHAR As Integer = &HC9
    12. Const EM_LINEINDEX As Integer = &HBB
    13. Const WS_CHILD As Integer = &H40000000
    14. Const WS_VISIBLE As Integer = &H10000000
    15. ' Für die optimale Bildqualität müsst ihr hier ein wenig rumspielen mit den zahlen...
    16. Const WM_USER As Short = &H400S
    17. Const WM_CAP_START As Short = &H400S
    18. Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
    19. Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
    20. Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
    21. Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
    22. Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
    23. Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11
    24. Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional ByRef x As Short = 0, Optional ByRef y As Short = 0, Optional ByRef nWidth As Short = 640, Optional ByRef nHeight As Short = 420, Optional ByRef nCameraID As Integer = 0) As IntPtr
    25. Dim previewHandle As IntPtr
    26. previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
    27. SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
    28. SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
    29. SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
    30. SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
    31. Return previewHandle
    32. End Function
    33. Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As Integer = 0)
    34. SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
    35. End Sub
    36. Sub Form1_FormClosing() Handles Me.FormClosing
    37. Me.Disconnect(videoHandle)
    38. End Sub
    39. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    40. Me.Close()
    41. End Sub
    42. End Class


    Ein weiteres Program ist "WinFormVBWebCam". Bei diesem Programm habe ich auch mal ein Bild gesehen. Leider aber nicht zuverlässig. Ich habe an meinem PC zwei Kameras angeschlossen.

    Ich habe mir auch u.A. Beispiele mit WIA oder auch WPF angesehen. Leider habe ich auch hier kein positives Ergebnis bekommen. Das einzige Programm, welches gut funktioniert hat, ist "CaptureImage". Hier der Quellcode:

    VB.NET-Quellcode

    1. Imports Emgu.CV
    2. Imports Emgu.CV.UI
    3. Imports Emgu.CV.Structure
    4. Public Class Form1
    5. Dim cap As New Capture() 'first line
    6. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7. Timer1.Stop()
    8. End Sub
    9. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    10. PictureBox1.Image = cap.QueryFrame.ToBitmap() 'Second line
    11. End Sub
    12. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    13. Timer1.Start()
    14. End Sub
    15. Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    16. PictureBox1.Left = 0
    17. PictureBox1.Top = 0
    18. PictureBox1.Width = Me.ClientSize.Width
    19. PictureBox1.Height = Me.ClientSize.Height
    20. End Sub
    21. End Class


    Das Problem hierbei ist, daß ich nicht weiß, wie ich ein Auswahlfenster für mehrere Kameras angezeigt bekomme.

    Am liebsten hätte ich eine Lösung mit WIA, da ich darüber schon einen Scanner ansteuern kann.

    Ich würde mir wünschen, wenn mir jemand helfen könnte.

    Vielen Dabnk schon mal im Voraus

    Verschoben. ~Trade

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Trade“ ()