Page 1 of 1

taking picture with the webcam

Posted: Fri Nov 27, 2009 9:42 pm
by gabriel
Hello:

is it possible to take a picture with the webcam? and how?

thanks

Re: taking picture with the webcam

Posted: Fri Nov 27, 2009 10:55 pm
by idle
Yes you can but what exactly do you want to do? There are a few ways you can do it.

Re: taking picture with the webcam

Posted: Sat Nov 28, 2009 7:39 am
by gabriel
thank you.
In fact, I want to take a picture and save it to a file when I click on a button.

Re: taking picture with the webcam

Posted: Sat Nov 28, 2009 11:18 pm
by idle

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_EDIT_COPY = #WM_CAP_START + 30
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_STOP = #WM_CAP_START + 68
#WM_CAP_SET_SCALE = #WM_CAP_START + 53

#WM_CAP_DLG_VIDEOFORMAT = #WM_CAP_START + 41
#WM_CAP_DLG_VIDEOSOURCE = #WM_CAP_START + 42
#WM_CAP_DLG_VIDEODISPLAY = #WM_CAP_START + 43
#WM_CAP_GET_VIDEOFORMAT = #WM_CAP_START + 44
#WM_CAP_SET_VIDEOFORMAT = #WM_CAP_START + 45
#WM_CAP_DLG_VIDEOCOMPRESSION = #WM_CAP_START + 46

Import "avicap32.lib"
CapCreateCaptureWindow.i(name.s, style.i, x.i, y.i, width.i, height.i, hWndParent.i, nId.i) As "_capCreateCaptureWindowA@32"
CapGetDriverDescription.i(index.i, name.i, cbName.i, ver.i, cbVer.i) As "_capGetDriverDescriptionA@20"
EndImport

;======if the compiler can't find the lib use this and call close library at the end of your code 
; Prototype.i ProtCapCreateCaptureWindow(name.s, style.i, x.i, y.i, width.i, height.i, hWndParent.i, nId.i)
; Prototype.i ProtCapGetDriverDescription(index.i, name.i, cbName.i, ver.i, cbVer.i)
; 
; If OpenLibrary(0, "avicap32.dll")
;    Global CapCreateCaptureWindow.ProtCapCreateCaptureWindow = GetFunction(0, "capCreateCaptureWindowA")
;    Global CapGetDriverDescription.ProtCapGetDriverDescription = GetFunction(0, "capGetDriverDescriptionA")
; EndIf


Procedure CapImage()
  Static sct
   
  sfile.s = SaveFileRequester("Save","c:\cap" + Str(sct) + ".bmp","*.bmp",1)
  image = GetClipboardImage(#PB_Any,32)

  If image 
     SaveImage(image,sfile)
     sct+1
  EndIf 
    
EndProcedure    
    
mwind = OpenWindow(#PB_Any,0,0,320,270,"WebCam",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

If mwind   
  Butcap = ButtonGadget(#PB_Any,5,245,60,20,"Capture")
  hCapWnd= CapCreateCaptureWindow("CapWindow", #WS_CHILD | #WS_VISIBLE,0,0,320,240,WindowID(mwind),0)
  SendMessage_(hCapWnd, #WM_CAP_DRIVER_CONNECT, 0, 0)
  SendMessage_(hCapWnd, #WM_CAP_SET_PREVIEW, 1, 0)
  SendMessage_(hCapWnd, #WM_CAP_SET_PREVIEWRATE, 10, 0)
  SendMessage_(hCapWnd, #WM_CAP_SET_SCALE,1,0)
  SendMessage_(hCapWnd, #WM_CAP_DLG_VIDEOFORMAT, 0, 0) 
  
  Repeat
   
  ev = WaitWindowEvent()
   
  If ev = #PB_Event_Gadget 
     evg = EventGadget()

     If evg = Butcap 
        PostMessage_(hCapWnd,#WM_CAP_EDIT_COPY,0,0)
        CapImage()
     EndIf
  EndIf      

Until ev = #PB_Event_CloseWindow

SendMessage_(hCapWnd, #WM_CAP_STOP, 0, 0)
SendMessage_(hCapWnd,#WM_CAP_DRIVER_DISCONNECT,0,0)
DestroyWindow_(hCapWnd)

EndIf 


Re: taking picture with the webcam

Posted: Sun Nov 29, 2009 1:15 am
by infratec
Hi Gabriel,

if you want to take single pictures and your webcam offers a twain driver,
than you can have a look to
http://www.purebasic.fr/english/viewtop ... 27&t=36281

I used a webcam for making pictures like a photo camera.

Bernd

Re: taking picture with the webcam

Posted: Mon Nov 30, 2009 12:06 pm
by gabriel
Thank you, all