El código de adquisición de la cámara en Windows solo necesita abrir el dispositivo y guardar las imágenes recopiladas como datos.
Código fuente del SDK de control de cámara VC
#include lt; windows.hgt
#include lt; > #include lt; vfw.hgt;
#pragma comment(lib, "vfw32.lib")
HWND ghWndCap //Manejador de la ventana de captura
CAPDRIVERCAPS gCapDriverCaps; //Capacidades del controlador de vídeo
CAPSTATUS gCapStatus; //Estado de la ventana de captura
char szCaptureFile[] = "MYCAP.AVI";
char gachBuffer[20];
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK StatusCallbackProc(HWND hWnd, int nID, LPSTR lpStatusText)
{
if(!ghWndCap)return FALSE; //Obtener el estado de la ventana de captura
capGetStatus(ghWndCap, amp; gCapStatus, sizeof(CAPSTATUS)); /Update El tamaño de la ventana de captura
SetWindowPos(ghWndCap, NULL, 0, 0, gCapStatus.uiImageWidth, gCapStatus.uiImageHeight, SWP_NOZORDER|SWP_NOMOVE);
if(nID== 0){/ /Borrar información de estado anterior
SetWindowText(ghWndCap, (LPSTR) "hello"
return (LRESULT)TRUE
}/ /Mostrar ID de estado y texto de estado
wsprintf(gachBuffer, "Status# d: s", nID, lpStatusText
SetWindowText(ghWndCap, (LPSTR)gachBuffer ); p>
return (LRESULT)TRUE;
}
LRESULT CALLBACK ErrorCallbackProc(HWND hWnd, int nErrID, LPSTR lpErrorText)
{
if(!ghWndCap)return FALSE;
if(nErrID==0)return TRUE; //Borrar errores antiguos
wsprintf(gachBuffer, "Error# d" , nErrID ); // Muestra la identificación del error y el texto
MessageBox(hWnd, lpErrorText, gachBuffer, MB_OK | MB_ICONEXCLAMATION
return (LRESULT) TRUE; >}
RESULTADO DE DEVOLUCIÓN DE LLAMADA FrameCallbackProc
(HWND hWnd, LPVIDEOHDR lpVHdr)
{
ARCHIVO *fp;
fp=fopen("caram.dat", "w"); p>
p>
if(!ghWndCap) return FALSE; //Asumimos que fp es un puntero de archivo .dat abierto
fwrite(lpVHdr-gt; lpData, 1, lpVHdr-gt; dwBufferLength, fp) ;
return (LRESULT)TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[]=TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0; p>
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL, IDI_APPLICATION);
wndclass .hCursor=LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass .lpszClassName=szAppName ;
if(!RegisterClass(amp; wndclass))
{
MessageBox(NULL, TEXT("¡Este programa requiere WindowsNT!" ), szAppName, MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName, TEXT("El programa Hola"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT , CW_USEDEFAULT, CW_USEDEFAULT , CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow
UpdateWindow(hwnd); (GetMessage(amp;msg, NULL, 0, 0))
{
TranslateMessage(amp;msg);
DispatchMessage(amp;msg);
}
devuelve msg.wParam;
}
LLAMADA DE RESULTADO WndProc(HWND hwnd, mensaje UINT, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
cambiar(mensaje)
{
caso WM_CREATE:
{
ghWndCap=capCreateCaptureWindow((LPSTR)"Capturar ventana", WS_CHILD|WS_VISIBLE, 0, 0, 300, 240, (HWND)hwnd, (int)0
capSetCallbackOnError(ghWndCap, (FARPROC)ErrorCallbackProc);
capSetCallbackOnStatus(ghWndCap, (FARPROC)StatusCallbackProc
capSetCallbackOnFrame(ghWndCap, (FARPROC)FrameCallbackProc); p>capDriverConnect(ghWndCap, 0); //Conecte la ventana de captura al controlador
//Obtenga las capacidades del controlador y coloque la información relevante en la variable de estructura gCapDriverCaps
capDriverGetCaps( ghWndCap , amp; gCapDriverCaps, sizeof(CAPDRIVERCAPS));
capPreviewRate(ghWndCap, 66); //Establece la velocidad de visualización del modo de vista previa
capPreview(ghWndCap, TRUE); /Iniciar modo de vista previa
if(gCapDriverCaps.fHasOverlay) //Compruebe si el controlador tiene capacidad de superposición
capOverlay(ghWndCap, TRUE //Iniciar modo de superposición
<); p>if (gCapDriverCaps.fHasDlgVideoSource)capDlgVideoSource(ghWndCap); //Cuadro de diálogo de fuente de videoif(gCapDriverCaps.fHasDlgVideoFormat)capDlgVideoFormat(ghWndCap); // Cuadro de diálogo de formato de video
if(gCapDriverCaps .fHasDlgVideoDisplay)capDlgVideoDisplay(ghWndCap); // Cuadro de diálogo de visualización de video
capFileSetCaptureFile(ghWndCap, szCaptureFile //Especificar el nombre del archivo de captura
capFileAlloc(ghWndCap, (1024L); * 1024L * 5)); //Asignar espacio de almacenamiento para los archivos de captura
capCaptureSequence(ghWndCap); //Comenzar a capturar la secuencia de video
capGrabFrame(ghWndCap); imagen
}
return 0;
caso WM_PAINT:
hdc=BeginPaint(hwnd,amp;ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("¡Hola, Windows98!"),-1,rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd,amp;ps);
devuelve 0;
caso WM_DESTROY:
{
capSetCallbackOnStatus( ghWndCap, NULL)
capSetCallbackOnError(ghWndCap, NULL);
capSetCallbackOnFrame(ghWndCap, NULL);
capCaptureAbort(ghWndCap); p>capDriverDisconnect(ghWndCap); //Desconecta la ventana de captura del controlador
PostQuitMessage(0);
}
return 0;
}
return DefWindowProc(hwnd, mensaje, wParam, lParam
}
);