Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

captura de video con web cam

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: captura de video con web cam Responder citando

Tengo que realizar un proyecto escolar en el que debo visualizar la imagen que provee una web cam dentro de una ventana de Builder C++. He escuchado por allí que existe una librería del Builder que se dedica a trabajar con ese tipo de cosas, y que el manejo de la web cam se realiza con los archivos de controladores.
De cualquier forma no tengo idea de como hacerlo, y les agradecería muchísimo vuestra ayuda.

mesak82
Volver arriba
Mensaje    Asunto: Responder citando

#include "c_cap.h"


Cap = new TCap (Handle);
Cap->EnumCapDrv();
if(Cap->pStringCapDrivers->Count>0)
Cap->Connect(0);

AnsiString Archivo;

if(Cap->pStringCapDrivers->Count>0)
{
Archivo="tufoto.bmp"
Cap->CaptureFrame(Archivo.c_str());
}
// Te envio ejemplo y archivo cabecera c_cap.h

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

// * Copyright (c) Allan Petersen, 2001.
// * This is a tutorial for a simple capture system using the win32 api
// * for accessing your webcam

#ifndef c_capH
#define c_capH
//---------------------------------------------------------------------------
#include <vfw.h> // video for windows library

class TCap
{
private:

protected:
HWND ParentHandle;
HWND hwndVideo;
CAPDRIVERCAPS CapDrvCaps; // driver capabilities

int SelectedDevice;

public:
TStringList *pStringCapDrivers;
int EnumCapDrv();
void Connect (int Selected);
void Format ();
void Source ();
void CaptureFrame (char *FileName);
__fastcall TCap(HWND Handle);
__fastcall ~TCap();
};


#endif


Espero te sirva.

INg. Gabriel Góngora Navarrete
TouchSoftware
Volver arriba
Mensaje    Asunto: Falto la implementacion!!! (Disculpa) Responder citando

c_cap.cpp

//---------------------------------------------------------------------------
/*
* Copyright (c) Allan Petersen, 2001.
* This is a tutorial for a simple capture system using the win32 api
* for accessing your webcam

* Contact Allan Petersen at <support@allanpetersen.com> or visit
* www.allanpetersen.com
*
*/
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <stdio.h>
#include "c_cap.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)

__fastcall TCap::TCap (HWND Handle)
{
// create video capture window
ParentHandle = Handle;
hwndVideo = capCreateCaptureWindow(
(LPSTR) "My Capture Window",
WS_CHILD | WS_VISIBLE,
0, 0, 300, 200,
(HWND) Handle,
(int) 1);

pStringCapDrivers = new TStringList;
SelectedDevice = -1;
}


__fastcall TCap::~TCap ()
{

delete pStringCapDrivers;

capPreview(hwndVideo, FALSE); // end preview
capDriverConnect(hwndVideo, SelectedDevice);
capDriverDisconnect(hwndVideo); // disconnect from driver
}

//---------------------------------------------------------------------------
// enumerate the installed capture drivers
//---------------------------------------------------------------------------
int TCap::EnumCapDrv ()
{
char szDeviceName[80]; // driver name
char szDeviceVersion[80]; // driver version
char str[161]; // concatinated string
int xcap; // counter

xcap = 0;
pStringCapDrivers->Clear ();
do {
if (capGetDriverDescription(xcap, szDeviceName, sizeof(szDeviceName),
szDeviceVersion, sizeof(szDeviceVersion))){

sprintf (str, "%s, %s", szDeviceName, szDeviceVersion);
pStringCapDrivers->AddObject (str, (TObject *)xcap);
}
else {
break;
}
xcap++;
} while (true);

return 0;
}

//---------------------------------------------------------------------------
// connecting to selected device and starts preview
//---------------------------------------------------------------------------
void TCap::Connect (int Selected)
{
CAPSTATUS CapStatus;
int hsize;

// capDlgVideoDisplay(hwndVideo);
// connect to the driver
if (SelectedDevice != -1) {
capPreview (hwndVideo, FALSE);
capDriverConnect(hwndVideo, SelectedDevice);
}

if (!capDriverConnect(hwndVideo, Selected)) {
// ---- Unable to connect to driver
return;
}

// update the driver capabilities
capDriverGetCaps (hwndVideo, sizeof(CAPDRIVERCAPS), &CapDrvCaps);

capDlgVideoFormat(ParentHandle);

// Are there new image dimensions
capGetStatus(hwndVideo, &CapStatus, sizeof(CAPSTATUS));

hsize = GetSystemMetrics(SM_CYMENU);
hsize += GetSystemMetrics(SM_CYCAPTION);

// ---- Rescaling the windows
SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth,
CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
SetWindowPos(ParentHandle, NULL, 0, hsize, CapStatus.uiImageWidth,
CapStatus.uiImageHeight+hsize, SWP_NOZORDER | SWP_NOMOVE);

// set preview rate to 33.3 miliseconds, or 30 FPS
capPreviewRate (hwndVideo, 33.3);

// start preview video
capPreview (hwndVideo, TRUE);

// ---- Remember selected device
SelectedDevice = Selected;
}

//---------------------------------------------------------------------------
// Get access to the video source format box
//---------------------------------------------------------------------------
void TCap::Format ()
{
int hsize;

CAPSTATUS CapStatus;

capDlgVideoFormat(hwndVideo);
// Are there new image dimensions
capGetStatus(hwndVideo, &CapStatus, sizeof(CAPSTATUS));

hsize = GetSystemMetrics(SM_CYMENU);
hsize += GetSystemMetrics(SM_CYCAPTION);

SetWindowPos(ParentHandle, NULL, 0, hsize, CapStatus.uiImageWidth,
CapStatus.uiImageHeight+hsize, SWP_NOZORDER | SWP_NOMOVE);
SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth,
CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
}
//---------------------------------------------------------------------------
// Get access to the video source dialog box
//---------------------------------------------------------------------------
void TCap::Source ()
{
capDlgVideoSource(hwndVideo);
}

//---------------------------------------------------------------------------
// capture a frame and save it
//---------------------------------------------------------------------------
void TCap::CaptureFrame (char *FileName)
{
capFileSaveDIB (hwndVideo, FileName);
}
Volver arriba
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.