Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delphi and webcamera catching picture

Status
Not open for further replies.

martinchrzan

Programmer
Dec 23, 2006
1
Hello! For my program I want to download pictures from webcam.I work in Delphi 7 and I(dont know where) red about unit AVICAP32.dll whitch contain this function. So I tried create simple program which by step show 100 pictures from webcam after I click button :

unit Main2;

interface

{-----------------------------------------------------------------------------}

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

{-----------------------------------------------------------------------------}

const
WM_USER = 1024;
WM_CAP_DRIVER_CONNECT = 1034;
WM_CAP_DRIVER_DISCONNECT = 1035;
WM_CAP_GET_FRAME = 1084;
WM_CAP_COPY = 1054;

WM_CAP_START = WM_USER;
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;
WM_CAP_SET_PREVIEW = WM_CAP_START + 50;

PICWIDTH = 640;
PICHEIGHT = 480;

{-----------------------------------------------------------------------------}

type
TfmMain = class(TForm)
Panel1 : TPanel;
Button2 : TButton;
procedure FormDestroy (Sender: TObject);
procedure FormCreate (Sender: TObject);
procedure Button2Click (Sender: TObject);
private
FCapHandle : THandle;
public

end;

{*****************************************************************************}

var
fmMain: TfmMain;

{*****************************************************************************}

implementation

{$R *.dfm}


{-----------------------------------------------------------------------------}

function capCreateCaptureWindow(lpszWindowName: LPCSTR; dwStyle: DWORD;
x, y, nWidth, nHeight: integer; hwndParent: HWND; nID: integer): HWND; stdcall;
external 'AVICAP32.DLL' name 'capCreateCaptureWindowA';

//------------------------------------------------------------------------------

procedure TfmMain.FormCreate(Sender: TObject);
begin
FCapHandle:= capCreateCaptureWindow('Video', WS_CHILD or WS_VISIBLE, 0, 0, PICWIDTH, PICHEIGHT, panel1.Handle, 1);

SendMessage(FCapHandle, WM_CAP_DRIVER_CONNECT,0,0);
SendMessage(FCapHandle, WM_CAP_DLG_VIDEOSOURCE,0,0);
SendMessage(FCapHandle, WM_CAP_DLG_VIDEOFORMAT,0,0);

end;

{-----------------------------------------------------------------------------}

procedure TfmMain.FormDestroy(Sender: TObject);
begin
SendMessage(FCapHandle,WM_CAP_DRIVER_DISCONNECT, 0, 0);
end;

{-----------------------------------------------------------------------------}

procedure TfmMain.Button2Click(Sender: TObject);
Var i:integer;
begin
For i:=1 to 100 do begin //Only for testing
SendMessage(FCapHandle,WM_CAP_GET_FRAME, 0, 0); end;
end;

end.



Program is running but is it too slow. Per 1 second it show just about 5 pictures. Does is something wrong in my program or is it error of Delphi ? In the aggregate all this system of catching pictures to panel dont conform me. I need just read single pixels in picture and a dont need to show this picture. It will be the best if the picture are saveing to some memory (canvas) – maybe it will be faster...
Thanks for advice
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top