Help with webcam or video stream
Help with webcam or video stream
Hi and thanks to all for helping.
I know there are several postings that talk about AVICAP and others for grabbing the video stream but I could not find anywhere a SIMPLE or should we say BASIC script that would do this.
Can someone please post a simple script to grab a video stream. I know in other languages such as ActionScript and such all you need to do is call a class and the paths. Can that be achieved here in less thank 20 lines?
Can someone post an example please.
Thanks again,
Carlos
I know there are several postings that talk about AVICAP and others for grabbing the video stream but I could not find anywhere a SIMPLE or should we say BASIC script that would do this.
Can someone please post a simple script to grab a video stream. I know in other languages such as ActionScript and such all you need to do is call a class and the paths. Can that be achieved here in less thank 20 lines?
Can someone post an example please.
Thanks again,
Carlos
I have a WebCam stream / frame capture project in progress that has 333 lines thus far. I plucked out some code, and with the following 19 lines, I am able to view a plain and simple WebCam preview window on my system. Your situation may require some additional device/system checks, so you may need to add some additional code. When you want to start capturing a stream, use SendMessage_(hWndC, #WM_CAP_SEQUENCE, 0, 0). You should also take a look at the CAPTUREPARMS and CAPDRIVERCAPS structures in the Win32 API. For more information, check out MSDN Video Capture
Code: Select all
;Code removed by Sparkie due to errors. Will fix and repost.
Last edited by Sparkie on Mon Jun 28, 2004 1:20 pm, edited 2 times in total.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
I just noticed I had OpenLibrary(1... and then CloseLibrary(0...
I edited the original code above and changed OpenLibrary(1 to OpenLibrary(0...
Don't know if that will fix your problem because the even the bad code executed without error here with PB 3.91 beta2 on WinXP.
I'm still learning about video capture so maybe someone else can provide a better answer.
I edited the original code above and changed OpenLibrary(1 to OpenLibrary(0...
Don't know if that will fix your problem because the even the bad code executed without error here with PB 3.91 beta2 on WinXP.
I'm still learning about video capture so maybe someone else can provide a better answer.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Seems I messed up while cutting those 20 lines of code from my original project. It's more than 20 lines now
but it should work without error.

Code: Select all
#WM_CAP_START = #WM_USER
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_DRIVER_GET_CAPS = #WM_CAP_START + 14
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_STOP = #WM_CAP_START + 68
If OpenWindow(0, 0, 0, 340, 260, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "Video capture")
If OpenLibrary(0, "C:\WINDOWS\system32\avicap32.dll")
*capAddress = IsFunction(0, "capCreateCaptureWindowA")
hWndC = CallFunctionFast(*capAddress, "My Capture Window", #WS_CHILD | #WS_VISIBLE, 10, 10, 320, 240, WindowID(),1)
SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEWRATE, 15, 0)
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
SendMessage_(hWndC, #WM_CAP_STOP, 0, 0)
SendMessage_(hWndC, #WM_CAP_DRIVER_DISCONNECT, 0, 0)
DestroyWindow_(hWndC)
CloseLibrary(0)
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Awesome thanks
Yhis is excellent on the first try the cam came out. And now I can finally see how to get it in a simple way.
Now I need to go for the thougher parts. Edge recognition, motion and other stuuf.
Thanks a lot. This is great.
What kind of app are you doing with this?
I was trying to get icamplay but the owner of the librarieas has not responded. I hear his stuff is pretty good.
Carlos
Now I need to go for the thougher parts. Edge recognition, motion and other stuuf.
Thanks a lot. This is great.
What kind of app are you doing with this?
I was trying to get icamplay but the owner of the librarieas has not responded. I hear his stuff is pretty good.
Carlos
chio
Same her
That is what I am doing exactly but for my office. But I am a total newbie on this.
Can you share some thoughts of what has gone well or bad. Or what not to try?
Thanks,
Carlos
Can you share some thoughts of what has gone well or bad. Or what not to try?
Thanks,
Carlos
chio
Re: Same her
Well I'm only about a week into this project so I can't say much yet in regards to the good or bad. Capturing stream and/or frame has been little or no problem. I've just started on motion detection and I'm almost certain this will be a little harder to tackle.chio wrote:That is what I am doing exactly but for my office. But I am a total newbie on this.
Can you share some thoughts of what has gone well or bad. Or what not to try?
Thanks,
Carlos
I'll let you know of my success/failures in the coming days.

What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Image capture
This comes from another threath but it works really well.
source.s="source.bmp" ;Switch "source.bmp" to your file
dest.s="dest.jpg" ;Also edit the destination
quality.l=7 ;7 is default. From 0-10
LoadImage(0,source.s)
UseJPEGImageEncoder()
SaveImage(0,dest.s,#PB_ImagePlugin_JPEG,quality.l)
source.s="source.bmp" ;Switch "source.bmp" to your file
dest.s="dest.jpg" ;Also edit the destination
quality.l=7 ;7 is default. From 0-10
LoadImage(0,source.s)
UseJPEGImageEncoder()
SaveImage(0,dest.s,#PB_ImagePlugin_JPEG,quality.l)
chio
Thanks PWS32. As I've said before, this is new territory for me so there may well be a better way to do this.PWS32 wrote:Hi Sparkie,
nice code !
howto can save a captured picture ?
Best regards,
Peter

I start off by creating an image placeholder for my frame image...
Code: Select all
CreateImage(0, 320, 240)
Code: Select all
SendMessage_(handle_to_your_capture_preview_window, #WM_CAP_GRAB_FRAME_NOSTOP, 0, 0)
SendMessage_(handle_to_your_capture_preview_window, #WM_CAP_EDIT_COPY, 0, 0)
img = GetClipboardData(#PB_ClipboardImage)
StartDrawing(ImageOutput())
DrawImage(img, 0, 0)
StopDrawing()
Code: Select all
SaveImage(0, your_file_name$, #PB_ImagePlugin_JPEG, 7)
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Hi,
im have the same problem and have remove the line:
SendMessage_(hWndC, #WM_CAP_GRAB_FRAME_NOSTOP, 0, 0)
and have add:
UseJPEGImageEncoder()
this works fine
cant understand what is #WM_CAP_GRAB_FRAME_NOSTOP
im found not information for this by google
Best regards,
Peter
im have the same problem and have remove the line:
SendMessage_(hWndC, #WM_CAP_GRAB_FRAME_NOSTOP, 0, 0)
and have add:
UseJPEGImageEncoder()
this works fine
cant understand what is #WM_CAP_GRAB_FRAME_NOSTOP
im found not information for this by google
Best regards,
Peter
Code: Select all
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #Button_0
;SendMessage_(hWndC, #WM_CAP_GRAB_FRAME_NOSTOP, 0, 0)
SendMessage_(hWndC, #WM_CAP_EDIT_COPY, 0, 0)
img = GetClipboardData(#PB_ClipboardImage)
StartDrawing(ImageOutput())
DrawImage(img, 0, 0)
StopDrawing()
UseJPEGImageEncoder()
SaveImage(0, "c:\test.jpg", #PB_ImagePlugin_JPEG, 7)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow