Fórum Webcam Delphi #453529
29/08/2013
0
Henrique Ribamar
Curtir tópico
+ 0Post mais votado
13/09/2013
Paulo Freire
Gostei + 1
Mais Posts
29/08/2013
Paulo Freire
Gostei + 0
29/08/2013
Deivison Melo
link para download:
[url]http://www.torry.net/vcl/mmedia/video/PSC.v5.2.3.0.zip[/url]
Abração!!
Espero ter ajudado!!!
Emanoel Deivison
Recife - PE
Gostei + 0
29/08/2013
Henrique Ribamar
Gostei + 0
29/08/2013
Paulo Freire
Vc esta usando DBXpress ????
GRAVAR UMA IMAGEM NUM CAMPO BLOB
(a query/dataset deve estar com State in [dsEdit,dsInsert]
procedure GravaFoto(DataSet : TDataSet; BlobFieldName, FileName : String);
GravaFoto(qryCliente,'FOTO','filename.jpg');
qryCliente - é a query/dataset com os dados
'FOTO' - string com o nome do campo blob
'filename' - string com o nome de arquivo jpg ou bmp
** você poderá substituir o 'filename' por: OpenPictureDialog1.FileName
-----
uses
Jpeg,
Graphics,
ExtDlgs,
Classes,
DB,
SysUtils,
ExtCtrls,
Dialogs,
Consts;
const
OffsetMemoryStream : Int64 = 0;
type
TTipoImagem = (tiBitmap, tiJpeg);
procedure GravaFoto(DataSet : TDataSet; BlobFieldName, FileName : String);
procedure GravaFoto(DataSet : TDataSet; BlobFieldName, FileName : String);
var
ext : string;
begin
if (DataSet.State in [dsEdit,dsInsert]) then begin
ext := UpperCase(ExtractFileExt(FileName));
if (ext <> '.BMP') and (ext <> '.JPG') and (ext <> '.JPEG') then begin
raise EAccessViolation.Create('Formado de imagem não suportado! Formato suportado: Jpeg ou Bitmap');
Abort;
end;
try
Jpg := TJpegImage.Create;
MemoryStream := TMemoryStream.Create;
Bitmap := TBitmap.Create;
if (ext = '.BMP') then begin
Bitmap.LoadFromFile(FileName);
Jpg.Assign(Bitmap);
Jpg.Compress;
end else
Jpg.LoadFromFile(FileName);
Jpg.SaveToStream(MemoryStream);
MemoryStream.Position := OffsetMemoryStream;
(DataSet.FieldByName(BlobFieldName) as TBlobField).BlobType := ftTypedBinary;
(DataSet.FieldByName(BlobFieldName) as TBlobField).LoadFromStream(MemoryStream);
finally
MemoryStream.Free;
Bitmap.Free;
Jpg.Free;
end;
end;
end;
Preciso saber o que vai fazer, pois minha Unit faz umas coisa que pra vc nem serve, por exemplo, trato imagens, exibo em webservice via ftp, eu circulo na filmagem da webcam um bloco/setor para detectar movimento ai tiro fotos, estou trabalhando com reconhecimento facial, então essa Unit ta muito grande, vc vai fazer tipo um cadastro de clientes/alunos com foto ???
Gostei + 0
30/08/2013
Paulo Freire
unit VideoCaptura;
USES Windows, Messages, SysUtils, Classes, ActiveX, Forms,
{$ifdef DXErr} DXErr9, {$endif}
DirectShow9;
CONST
WM_GRAPHNOTIFY = WM_APP+1;
WM_NewFrame = WM_User+2; // Used to inform application that a new video
// frame has arrived. Necessary only, if
// application hasn't defined a callback
// routine via TVideoSample.SetCallBack(...).
CONST { Copied from OLE2.pas }
{$EXTERNALSYM IID_IUnknown}
IID_IUnknown: TGUID = (
D1:$00000000;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));
TYPE
TPLAYSTATE = (PS_Stopped,
{PS_Init,}
PS_Paused,
PS_Running);
FUNCTION StartVideo(CaptureDeviceName: string; Visible: boolean; VAR DeviceSelected: string):HRESULT;
FUNCTION PausaVideo: HResult; // Pause running video
FUNCTION ResumeVideo: HResult; // Re-start paused video
FUNCTION StopVideo: HResult;
function GetImageBuffer(VAR pb : pbytearray; var Size: integer): HResult;
FUNCTION SetPreviewState(nShow: boolean): HRESULT;
FUNCTION ShowPropertyDialog: HResult;
FUNCTION ShowPropertyDialog_CaptureStream: HResult;
FUNCTION GetVideoPropAmpEx( Prop : TVideoProcAmpProperty;
VAR pMin, pMax,
pSteppingDelta,
pDefault : longint;
VAR pCapsFlags : TVideoProcAmpFlags;
VAR pActual : longint): HResult;
FUNCTION VideoCaptura.StartVideo(DeviceName: string; Visible: boolean; VAR DeviceSelected: string):HRESULT;
BEGIN
pIBFVideoSource := nil;
FVisible := Visible;
// Attach the filter graph to the capture graph
Result := pICapGraphBuild2.SetFiltergraph(pIGraphBuilder);
if (FAILED(Result)) then
begin
// Failed to set capture filter graph!
exit;
end;
// Use the system device enumerator and class enumerator to find
// a video capture/preview device, such as a desktop USB video camera.
Result := ConnectToCaptureDevice(CaptureDeviceName, DeviceSelected, pIBFVideoSource);
if (FAILED(Result)) then
begin
exit;
end;
LoadListOfResolution;
Result := RestartVideo;
end;
FUNCTION VideoCaptura.PausaVideo: HResult;
BEGIN
IF g_psCurrent = PS_Paused
then begin
Result := S_OK;
EXIT;
end;
IF g_psCurrent = PS_Running then
begin
Result := pIMediaControl.Pause;
if Succeeded(Result) then
g_psCurrent := PS_Paused;
end
else Result := S_FALSE;
END;
FUNCTION VideoCaptura.ResumeVideo: HResult;
BEGIN
IF g_psCurrent = PS_Running then
begin
Result := S_OK;
EXIT;
end;
IF g_psCurrent = PS_Paused then
begin
Result := pIMediaControl.Run;
if Succeeded(Result) then
g_psCurrent := PS_Running;
end
else Result := S_FALSE;
END;
FUNCTION VideoCaptura.StopVideo: HResult;
BEGIN
// Stop previewing video data
Result := pIMediaControl.StopWhenReady();
g_psCurrent := PS_Stopped;
SetLength(FormatArr, 0);
END;
No seu Form.Active, colque um combox para lsta as WebCams instaladas
var
DeviceList : TStringList;
begin
if Activated then
exit;
Activated := true;
// Listas as webCams ou Cameras IPs
DeviceList := TStringList.Create;
VideoCapture.GetListOfDevices(DeviceList);
if DeviceList.Count < 1 then
begin
// Se não encontrar cameras fecha a aplicação
Caption := 'WVisitante [Não foi encontrado WebCam]';
MessageDlg('Não há serviço de webcam ativo.'#10'Informação...', mtError, [mbOK], 0);
exit;
end else
begin
Combobox1.items.Assign(DeviceList);
Combobox1.ItemIndex := 0;
btnStart.Enabled := true;
end;
Unit CapturaFrames;
interface
USES Windows, Messages, Controls, Forms, SysUtils, Graphics, Classes,
AppEvnts, MMSystem, DirectShow9, JPEG,
VSample;
CONST
CBufferCnt = 3;
procedure GetListOfDevices(DeviceList: TStringList);
procedure VideoStop;
procedure VideoPause;
procedure VideoResume;
function VideoStart(DeviceName: string): integer;
procedure GetBitmap(BMP: TBitmap);
procedure GetJpeg(JPG: TJPEGImage);
procedure SetDisplayCanvas(Canvas: TCanvas);
procedure ShowProperty;
procedure ShowProperty_Stream;
procedure CapturaFrames.GetListOfDevices(DeviceList: TStringList);
begin
GetCaptureDeviceList(DeviceList);
end;
procedure CapturaFrames.VideoPause;
begin
if not assigned(VideoSample) then
exit;
VideoSample.PauseVideo;
end;
procedure CapturaFrames.VideoResume;
begin
if not assigned(VideoSample) then
exit;
VideoSample.ResumeVideo;
end;
procedure CapturaFrames.VideoStop;
begin
fFPS := 0;
if not assigned(VideoSample) then
exit;
try
VideoSample.Free;
VideoSample := nil;
except
end;
fVideoRunning := false;
end;
function CapturaFrames.VideoStart(DeviceName: string): integer;
VAR
hr : HResult;
st : string;
W, H : integer;
FourCC : cardinal;
begin
fSkipCnt := 0;
fFrameCnt := 0;
f30FrameTick := 0;
fFPS := 0;
fImageUnpacked := false;
Result := 0;
if assigned(VideoSample) then
VideoStop;
VideoSample := TVideoSample.Create(Application.MainForm.Handle, false, 0, HR); // Abrindo RGB 24bits
try
hr := VideoSample.StartVideo(DeviceName, false, st) // Não abrir, destruir o display
except
hr := -1;
end;
if Failed(hr)
then begin
VideoStop;
// SpeedButton_RunVideo.Down := false;
// ShowMessage(DXGetErrorDescription9A(hr));
Result := 1;
end
else begin
hr := VideoSample.GetStreamInfo(W, H, FourCC);
IF Failed(HR)
then begin
VideoStop;
Result := 1;
end
else BEGIN
fWidth := W;
fHeight := H;
fFourCC := FourCC;
FBitmap.PixelFormat := pf24bit;
FBitmap.Width := W;
FBitmap.Height := H;
VideoSample.SetCallBack(CallBack); // Modificado Paulo - 27/06/2007
END;
end;
end;
procedure CapturaFrames.GetBitmap(BMP: TBitmap);
begin
IF not fImageUnpacked then
UnpackFrame(fImagePtrSize[fImagePtrIndex], fImagePtr[fImagePtrIndex]);
BMP.Assign(fBitmap);
(*
BMP.PixelFormat := pf24bit;
BMP.Width := fBitmap.Width;
BMP.Height := fBitmap.Height;
move(fBitmap.ScanLine[fBitmap.Height-1]^, BMP.ScanLine[BMP.height-1]^, BMP.Height*BMP.Width*3);
//BMP.Canvas.Draw(0, 0, fBitmap);
*)
end;
procedure CapturaFrames.SetDisplayCanvas(Canvas: TCanvas);
begin
fDisplayCanvas := Canvas;
end;
procedure CapturaFrames.ShowProperty;
begin
VideoSample.ShowPropertyDialog;
end;
procedure CapturaFrames.GetJpeg(JPG: TJPEGImage);
begin
IF not fImageUnpacked then
UnpackFrame(fImagePtrSize[fImagePtrIndex], fImagePtr[fImagePtrIndex]);
JPG.Assign(fJpeg);
end;
End.
Acho que mais facil eu te montar um exemplo, qualquer coisa dá um grito.
Gostei + 0
30/08/2013
Henrique Ribamar
Gostei + 0
30/08/2013
Henrique Ribamar
Gostei + 0
30/08/2013
Paulo Freire
Beleza, me passa mais ou meno sua tabela de clientes, id, nome, foto(blob) isso mesmo ? vou criar uma similar e criar um exemplo e te mando, mas só posso fazer isso na segunda, ok
É muito simples.
Gostei + 0
30/08/2013
Henrique Ribamar
Gostei + 0
02/09/2013
Paulo Freire
https://skydrive.live.com/redir?resid=90738B8009A49B94!384&authkey=!AMtAMh_J4ATbudM
Gostei + 0
06/09/2013
Henrique Ribamar
Gostei + 0
13/09/2013
Paulo Freire
Gostei + 0
13/09/2013
Paulo Freire
Gostei + 0
17/09/2013
Henrique Ribamar
Gostei + 0
17/09/2013
Henrique Ribamar
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)