Mensaje    Asunto: Captura de video con camras web Responder citando

Código:

Código:

//---------------------------------------------------------------------------
/*
* Copyright (c) Allan Petersen, 2001.
* This is a tutorial for a simple capture system using the win32 api
* for accessing your webcam
*
* (c) Copyright 2001, Allan Petersen
* ALL RIGHTS RESERVED
*
* Contact Allan Petersen at <support@allanpetersen.com> or visit
* www.allanpetersen.com
*
*/
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <stdio.h>
#include "c_cap.h"
#include "ServerVideo.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,
                    frmServerVideo->panelCaptura->Handle,
                    (int) 0);

              /*      w = capCreateCaptureWindow("Mi Video",
                    WS_CHILD | WS_VISIBLE,
                       1, 1, 320, 240,
                       Panel1->Handle, 0); */


    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);
}

 


Archivode cabecera

Código:

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

#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
 

_________________
Ing. Gabriel Góngora Navarrete
TouchSoftwares Inc

http://www.touchsoftwares.com