Video capture issues
Posted: Sun Mar 19, 2023 3:54 pm
Hi,
I'm trying to display video from a low cost USB video capture device (from Amazon), whilst displaying the video I also want to capture stills for further processing.
I know the capture device works in the standard Win10 webcam app and OBS. I found various bits of sample code on this forum, however they only display solid black.I've also tried this on a laptop with a built in camera - same results.
Running w10. and PB 6.00
Any thoughts?
I'm trying to display video from a low cost USB video capture device (from Amazon), whilst displaying the video I also want to capture stills for further processing.
I know the capture device works in the standard Win10 webcam app and OBS. I found various bits of sample code on this forum, however they only display solid black.I've also tried this on a laptop with a built in camera - same results.
Running w10. and PB 6.00
Code: Select all
cwFlags = #WS_CHILD | #WS_VISIBLE
wFlags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
If OpenWindow(0, 0, 0, 660, 500, "Webcam Example", wFlags)
If OpenLibrary(0, "avicap32.dll")
*capAddress = GetFunction(0, "capCreateCaptureWindowA")
If *capAddress
hWnd = CallFunctionFast(*capAddress, 0, cwFlags, 10, 10, 640, 480, WindowID(0), 0)
If hWnd
If SendMessage_(hWnd, #WM_CAP_DRIVER_CONNECT, 0, 0)
Delay(100)
x=SendMessage_(hWnd, #WM_CAP_SET_SCALE, #True, 0) ; was true
Debug "#WM_CAP_SET_SCALE:"+x
x=SendMessage_(hWnd, #WM_CAP_SET_PREVIEWRATE, 15, 0) ; was 15ms
Debug "#WM_CAP_SET_PREVIEWRATE:"+x
x=SendMessage_(hWnd, #WM_CAP_SET_PREVIEW, #True, 0)
Debug "#WM_CAP_SET_PREVIEW:"+x
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
error$ = "Webcam terminated."
Else
error$ = "Unable to connect to webcam."
EndIf
Else
error$ = "Unable to create capture window."
EndIf
Else
error$ = "Unable to locate capture function."
EndIf
SendMessage_(hWnd, #WM_CAP_STOP, 0, 0)
SendMessage_(hWnd, #WM_CAP_DRIVER_DISCONNECT, 0, 0)
DestroyWindow_(hWnd)
CloseLibrary(0)
Else
error$ = "Unable to open AVI library."
EndIf
MessageRequester("Webcam", error$)
Endif