Bestimmte Webcam direkt ansprechen

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Captain T.

    Bestimmte Webcam direkt ansprechen

    Hallo,

    Vorhaben: Ich hoffe ihr könnt mir weiter helfen und zwar bastle ich mir grade meine eigene Oberfläche für meinen CarPC. In diese möchte ich eine Webcam als Rückfahrkamera integrieren. Eine Picturebox soll das Livebild auf Buttondruck direkt anzeigen. Ich benutze dazu den angehängten Code.

    Problem: Wenn ich nun auf den Button drücke öffnet sich zuerst ein weiteres Fenster, bei dem ich eine Videoquelle aussuchen soll was ich aber nicht möchte. Ich hab auch schon probiert die nCameraID zu ändern. Sobald diese nicht 0 ist kommt auch das Auswahlfenster nicht mehr aber meine Picturebox ist einfach nur schwarz.

    Frage: Wie bekomme ich diese nCameraID meiner Webcam heraus oder gibt es andere Lösungen dafür?

    Bin für jede Hilfe dankbar

    Quellcode

    1. Dim videoHandle As IntPtr
    2. Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    3. 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
    4. Const EM_LINEFROMCHAR As Integer = &HC9
    5. Const EM_LINEINDEX As Integer = &HBB
    6. Const WS_CHILD As Integer = &H40000000
    7. Const WS_VISIBLE As Integer = &H10000000
    8. Const WM_USER As Short = &H400S
    9. Const WM_CAP_START As Short = &H400S
    10. Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
    11. Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
    12. Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
    13. Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
    14. Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
    15. Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11
    16. 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
    17. Dim previewHandle As IntPtr
    18. previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
    19. SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
    20. SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
    21. SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
    22. SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
    23. Return previewHandle
    24. End Function
    25. Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As Integer = 0)
    26. SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
    27. End Sub
    28. Sub Form1_FormClosing() Handles Me.FormClosing
    29. Me.Disconnect(videoHandle)
    30. End Sub
    31. Sub Button1_Click() Handles button1.Click
    32. videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
    33. End Sub
    Ich versuche grade herauszufinden wie mir diese beiden links weiterhelfen sollen. Mit mit beiden Programmen komme ich trotzdem nich um das erwähnte Fenster "Videoquellen" herum, in dem ich eine meiner Webcams wählen muss :(
    Gibt es keine Möglichkeit die am PC angeschlossenen Webcams zu analisieren und dann den Pictureboxen zuzuweisen?