Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   socket y webcam (https://www.clubdelphi.com/foros/showthread.php?t=51879)

angelp4492 03-01-2008 01:40:50

socket y webcam
 
Hola como estan?

estuve probando este codigo y va muy bien, pero mi duda es como podria mandar la imagen via socket.



Código Delphi [-]
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    OpenVideo: TButton;
    CloseVideo: TButton;
    GrabFrame: TButton;
    SaveBmp: TButton;
    StartAvi: TButton;
    StopAvi: TButton;
    SaveDialog1: TSaveDialog;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure CloseVideoClick(Sender: TObject);
    procedure GrabFrameClick(Sender: TObject);
    procedure SaveBmpClick(Sender: TObject);
    procedure StartAviClick(Sender: TObject);
    procedure StopAviClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
     hWndC : THandle;
      CapturingAVI : bool;
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
 const WM_CAP_START = WM_USER;
const WM_CAP_STOP = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
const WM_CAP_SAVEDIB = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
const WM_CAP_SEQUENCE = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
 
function capCreateCaptureWindowA(lpszWindowName : PCHAR;
  dwStyle : longint;
  x : integer;
  y : integer;
  nWidth : integer;
  nHeight : integer;
  ParentWin : HWND;
  nId : integer): HWND;
  STDCALL EXTERNAL 'AVICAP32.DLL';
 

procedure TForm1.FormCreate(Sender: TObject);
begin
  CapturingAVI := false;
  hWndC := 0;
  SaveDialog1.Options :=
  [ofHideReadOnly, ofNoChangeDir, ofPathMustExist]

end;
procedure TForm1.CloseVideoClick(Sender: TObject);
begin
 if hWndC <> 0 then begin
  SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
  hWndC := 0;
  end;

end;
procedure TForm1.GrabFrameClick(Sender: TObject);
begin
if hWndC <> 0 then
  SendMessage(hWndC, WM_CAP_GRAB_FRAME, 0, 0);

end;
procedure TForm1.SaveBmpClick(Sender: TObject);
begin
if hWndC <> 0 then begin
  SaveDialog1.DefaultExt := 'bmp';
  SaveDialog1.Filter := 'Bitmap files (*.bmp)|*.bmp';
  if SaveDialog1.Execute then
  SendMessage(hWndC,
  WM_CAP_SAVEDIB,
  0,
  longint(pchar(SaveDialog1.FileName)));
  end;

end;
procedure TForm1.StartAviClick(Sender: TObject);
begin
 if hWndC <> 0 then begin
  SaveDialog1.DefaultExt := 'avi';
  SaveDialog1.Filter := 'AVI files (*.avi)|*.avi';
  if SaveDialog1.Execute then begin
  CapturingAVI := true;
  SendMessage(hWndC,
  WM_CAP_FILE_SET_CAPTURE_FILEA,
  0,
  Longint(pchar(SaveDialog1.FileName)));
  SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
  end;
  end;

end;
procedure TForm1.StopAviClick(Sender: TObject);
begin
SendMessage(hWndC, WM_CAP_STOP, 0, 0);
  CapturingAVI := false;
  end;
 

procedure TForm1.Timer1Timer(Sender: TObject);
begin
hWndC := capCreateCaptureWindowA('My Own Capture Window',
  WS_CHILD or WS_VISIBLE ,
  Panel1.Left,
  Panel1.Top,
  Panel1.Width,
  Panel1.Height,
  Form1.Handle,
  0);
  if hWndC <> 0 then
  SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
end;
end.

cHackAll 03-01-2008 02:28:48

Varias formas; la primera es utilizar un componente que te guarde los frames capturados en un stream.... segun te van llegando los mandas por socket como tal;

Otra es de tiempo en tiempo enviar el archivo .AVI y al recivirlo en el otro host reproducirlo... esperando al finalizar el siguiente AVI

por ultimo se me ocurre que agrarres el BMP; lo conviertas a un formato LossLess como el JPEG.... y lo envies... cada vez que recives la imagen en el host destino (cliente?) lo muestras...

Otras formas implican aprender algoritmos mas complicados. pero que al final lo que hacen es enviarte imagen por imagen. (eso es un video)

Saludos


La franja horaria es GMT +2. Ahora son las 12:12:47.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi