Recent

Author Topic: [Windows] How capture picture from webcam ?  (Read 27567 times)

seba22

  • Full Member
  • ***
  • Posts: 136
[Windows] How capture picture from webcam ?
« on: May 30, 2010, 08:52:25 am »
Welcome,

I'm trying to write application what will allow me to capture pictures from USB camera. (for surveillance).

I read about "http://wiki.lazarus.freepascal.org/SysRec#Usage" and downloaded sources but i can't compile it.


Code: [Select]
Recorder.pas(272,27) Error: Incompatible type for arg no. 1: Got "Boolean", expected "TShowInTaskbar"
If anyone have working code, please share.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: [Windows] How capture picture from webcam ?
« Reply #1 on: May 30, 2010, 09:47:28 am »
Is it really that hard to find the solution?

From Forms.pp

Code: [Select]
TShowInTaskbar = (
stDefault,  // use default rules for showing taskbar item
stAlways,   // always show taskbar item for the form
stNever     // never show taskbar item for the form
);

Yawn...

seba22

  • Full Member
  • ***
  • Posts: 136
Re: [Windows] How capture picture from webcam ?
« Reply #2 on: May 30, 2010, 10:06:18 am »
I comment
Code: [Select]
//{$R *.res} and start working.

I test it on my webcam, i can see image. So that's great.

But i don't want display image to user, i don't need capture 24 frame video to avi.
I just want to take shoot (picture) (.jpg) every minute  and send that file to my surveillance image server.


So please tell me just one thing. how can i capture just one frame and save it to file.

I read that u should use CapGrabFrame but i can't find any example.

Regards

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: [Windows] How capture picture from webcam ?
« Reply #3 on: May 30, 2010, 10:52:23 am »

herux

  • Full Member
  • ***
  • Posts: 102
Re: [Windows] How capture picture from webcam ?
« Reply #4 on: May 30, 2010, 09:29:09 pm »
you can use the callbacks function as events and call capSetCallbackOnframe function on vfw.pas.

save every image to file on that events

seba22

  • Full Member
  • ***
  • Posts: 136
Re: [Windows] How capture picture from webcam ?
« Reply #5 on: May 31, 2010, 02:35:12 pm »
Welcome,

I have to be blind.
Example is inside source file...

I add little change. Because i want put image into Timage. Next i can save it using image1.picture.SaveToFile('myfile.jpg');

Code: [Select]
procedure TForm1.CapGrabFrame(Destination: TBitmap);
begin
  capGrabFrameNoStop(FCapHandle);        // Copy the current frame to a buffer
  capEditCopy(FCapHandle);               // Copy from buffer to the clipboard
  if Clipboard.HasFormat(CF_Bitmap) then // Load the frame/image from clipboard
{$IFDEF FPC}                             // Lazarus way ;)
  Destination.LoadFromClipboardFormat(CF_Bitmap);
  image1.Picture.LoadFromClipboardFormat(CF_Bitmap);
  EmptyClipboard;
{$ELSE}                                  // Delphi compatibility
   Destination.LoadFromClipboardFormat(CF_Bitmap, ClipBoard.GetAsHandle(CF_Bitmap), 0);
image1.Picture.LoadFromClipboardFormat(CF_Bitmap, ClipBoard.GetAsHandle(CF_Bitmap), 0);
{$ENDIF}

end;     


I have last question.

How can i change capture resolution ?
I think all modern camera have 640, so i want use this as default.
Now it's 320 px.

Any idea ?

herux

  • Full Member
  • ***
  • Posts: 102
Re: [Windows] How capture picture from webcam ?
« Reply #6 on: May 31, 2010, 06:57:07 pm »
Using clipboard is not a good idea.

Quote
How can i change capture resolution ?

use this
 function capSetVideoFormat(hwnd: HWND; s: PVOID; wSize: WORD): BOOL;

seba22

  • Full Member
  • ***
  • Posts: 136
Re: [Windows] How capture picture from webcam ?
« Reply #7 on: June 01, 2010, 02:20:07 am »
Welcome,

I'm trying make it working but can't.

I found only one example here  http://bczlw.com/Article/FAQ/bianchengyuyan/VC-MFC/2007-3-6/2007030608592660.html


And i wan't try to use it


Code: [Select]
procedure TVideo.Button1Click(Sender: TObject);
var
        vfs :WORD;
lpBmpInfo:BITMAPINFO ;
begin
CapCreate;
CapConnect;
vfs := sizeof(BITMAPINFO);
capGetVideoFormat(FCapHandle,lpBmpInfo,vfs);
lpBmpInfo.bmiHeader.biWidth  := 640 ;
lpBmpInfo.bmiHeader.biHeight := 480 ;
lpBmpInfo.bmiHeader.biBitCount := 8 ;
lpBmpInfo.bmiHeader.biPlanes   := 1 ;
lpBmpInfo.bmiHeader.biClrUsed  := 0 ;
lpBmpInfo.bmiHeader.biXPelsPerMeter := 0 ;
lpBmpInfo.bmiHeader.biSize          := 40 ;
lpBmpInfo.bmiHeader.biYPelsPerMeter := 0 ;
lpBmpInfo.bmiHeader.biCompression   := BI_RGB ;
lpBmpInfo.bmiHeader.biClrImportant  := 0 ;
lpBmpInfo.bmiHeader.biSizeImage     :=          lpBmpInfo.bmiHeader.biWidth * lpBmpInfo.bmiHeader.biHeight * lpBmpInfo.bmiHeader.biBitCount /8 ;
         
capSetVideoFormat(FCapHandle,lpBmpInfo,vfs) ;


end;         
But it don't like work
Code: [Select]
Recorder.pas(70,18) Hint: Parameter "Handle" not used
Recorder.pas(190,39) Error: Incompatible type for arg no. 2: Got "BITMAPINFO", expected "Pointer"
VFW.pas(4070,13) Hint: Found declaration: capGetVideoFormat(LongWord,Pointer,Word):DWord;
Recorder.pas(201,144) Hint: use DIV instead to get an integer result
Recorder.pas(201,141) Error: Incompatible types: got "Extended" expected "LongWord"
Recorder.pas(202,49) Error: Incompatible type for arg no. 2: Got "BITMAPINFO", expected "Pointer"
VFW.pas(4080,13) Hint: Found declaration: capSetVideoFormat(LongWord,Pointer,Word):LongBool;
Recorder.pas(241) Fatal: There were 3 errors compiling module, stopping

I think we are close to find solution...

rezgui

  • Newbie
  • Posts: 1
Re: [Windows] How capture picture from webcam ? solution to grap image
« Reply #8 on: August 23, 2010, 07:28:45 am »
Welcome,

I'm trying to write application what will allow me to capture pictures from USB camera. (for surveillance).

I read about "http://wiki.lazarus.freepascal.org/SysRec#Usage" and downloaded sources but i can't compile it.


Code: [Select]
Recorder.pas(272,27) Error: Incompatible type for arg no. 1: Got "Boolean", expected "TShowInTaskbar"
If anyone have working code, please share.

solution is :

  if Clipboard.FindPictureFormatID = Windows.CF_BITMAP then
  begin
    OpenClipboard(FCapHandle); // Handle is my form's handle
    Destination.Bitmap.Handle := HBITMAP(GetClipboardData(Windows.CF_BITMAP));
    CloseClipboard;
  end; 


nccwarp9

  • Newbie
  • Posts: 2
Re: [Windows] How capture picture from webcam ?
« Reply #9 on: August 18, 2014, 09:29:10 pm »
I know that this thread is very old but I need to ask as there is no info on this, I looked.

Have you managed to get webcam frame to Timage ?

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: [Windows] How capture picture from webcam ?
« Reply #10 on: August 18, 2014, 09:42:48 pm »
Try this button...
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

nccwarp9

  • Newbie
  • Posts: 2
Re: [Windows] How capture picture from webcam ?
« Reply #11 on: August 19, 2014, 10:49:14 am »

 

TinyPortal © 2005-2018