• Miércoles 8 de Mayo de 2024, 22:02

Autor Tema:  Capturar Imagen Videocamara  (Leído 7843 veces)

chabolis

  • Nuevo Miembro
  • *
  • Mensajes: 5
    • Ver Perfil
Capturar Imagen Videocamara
« en: Lunes 29 de Noviembre de 2004, 19:59 »
0
Necesito capturar la imagen de una videocamara en C++ para procesar la imagen a través de una tarjeta capturadora de video. Tambien puede que me sirva una webcam conectada a usb

NOVA_BUILDER

  • Miembro activo
  • **
  • Mensajes: 37
    • Ver Perfil
Re: Capturar Imagen Videocamara
« Respuesta #1 en: Miércoles 1 de Diciembre de 2004, 00:39 »
0
<_<  TALVES PODRIAS CAPTURAR LA IMAGEN CON EL CLIPBOARD() Y POSTERIOMENTE CARGARLO A UN  IMAGE O... CON EL GETCLIPBOARD()

TALVEZ TE SIRVA... :comp:
EL QUE LEE SOBRE VB...ES PORQUE ESTA APRENDIENDO A LEER.

chabolis

  • Nuevo Miembro
  • *
  • Mensajes: 5
    • Ver Perfil
Re: Capturar Imagen Videocamara
« Respuesta #2 en: Sábado 11 de Diciembre de 2004, 01:09 »
0
Con esto no consigo hacerlo, a ver si alguien me puede dar más ideas
Gracias

chabolis

  • Nuevo Miembro
  • *
  • Mensajes: 5
    • Ver Perfil
Re: Capturar Imagen Videocamara
« Respuesta #3 en: Martes 28 de Diciembre de 2004, 06:29 »
0
NAdie me puede ayudar?

werix

  • Nuevo Miembro
  • *
  • Mensajes: 3
    • Ver Perfil
Re: Capturar Imagen Videocamara
« Respuesta #4 en: Viernes 14 de Enero de 2005, 15:47 »
0
Existe un componente de video que puedes instalar.... se llama TVVIDEOGRABBER (o algo asi), buscalo en internet e instalalo como un componente cualquiera.

Ojala te sirva.

touch

  • Nuevo Miembro
  • *
  • Mensajes: 13
    • Ver Perfil
Re: Capturar Imagen Videocamara
« Respuesta #5 en: Sábado 29 de Enero de 2005, 18:23 »
0
Clase para captura de video con webcam , me funciona muy bien

Código: Text
  1.  
  2. //---------------------------------------------------------------------------
  3. /*
  4.  * Copyright (c) Allan Petersen, 2001.
  5.  * This is a tutorial for a simple capture system using the win32 api
  6.  * for accessing your webcam
  7.  *
  8.  * (c) Copyright 2001, Allan Petersen
  9.  * ALL RIGHTS RESERVED
  10.  * Permission to use, copy, modify, and distribute this software for
  11.  * any purpose and without fee is hereby granted, provided that the above
  12.  * copyright notice appear in all copies and that both the copyright notice
  13.  * and this permission notice appear in supporting documentation, and that
  14.  * the name of Allan Petersen not be used in advertising
  15.  * or publicity pertaining to distribution of the software without specific,
  16.  * written prior permission.
  17.  *
  18.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  19.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  20.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  21.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL ALLAN
  22.  * PETERSEN BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  23.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  24.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  25.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  26.  * THIRD PARTIES, WHETHER OR NOT ALLAN PETERSEN HAS BEEN
  27.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  28.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  29.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  30.  *
  31.  * Contact Allan Petersen at <support@allanpetersen.com> or visit
  32.  * www.allanpetersen.com
  33.  *
  34.  */
  35. //---------------------------------------------------------------------------
  36.  
  37. #include <vcl.h>
  38. #pragma hdrstop
  39.  
  40. #include <stdio.h>
  41. #include "c_cap.h"
  42.  
  43. //---------------------------------------------------------------------------
  44. #pragma package(smart_init)
  45. //---------------------------------------------------------------------------
  46. LRESULT CALLBACK fcb(HWND w, LPVIDEOHDR h)
  47. {
  48.         // En 'h->lpData' tenemos los datos del fotograma
  49.         // antes de ser visualizado. En este ejemplo a 320x240 24bits,
  50.         // por lo tanto la información de cada pixel estara del siguiente
  51.         // modo BLUE-GREEN-RED.... o sea, 3 bytes por cada pixel
  52.         // En 'h->dwBytesUsed' tenemos la cantidad de bytes de la imagen
  53.         // Para este ejemplo, como demostración vamos a poner la imagen
  54.         // en negativo. Aquí podriamos tanto modificar la imagen antes
  55.         // de ser vista o bien comprimir estos datos y enviarlos por la red...
  56.    typedef struct {BYTE b,g,r;} PIXEL;
  57.     char *DatosDib;
  58.     DatosDib=new char[h->dwBytesUsed];
  59.     int j=0;
  60.     for (DWORD i=0; i<h->dwBytesUsed/3; i++)
  61.     {
  62.  
  63.         PIXEL *pixel = &((PIXEL*)h->lpData)[i];
  64.        /* pixel->r = ~pixel->r;
  65.         pixel->g = ~pixel->g;
  66.         pixel->b = ~pixel->b; */
  67.         DatosDib[j]=pixel->r;        j++;
  68.         DatosDib[j]=pixel->g;        j++;
  69.         DatosDib[j]=pixel->b;        j++;
  70.     }
  71. //    frmTomarFoto->Image1->Assig(h->lpdata);
  72.  
  73.         // devolvemos TRUE para que la función siga capturando mas fotogramas
  74.   return TRUE;
  75.  
  76. }
  77. //---------------------------------------------------------------------------
  78.  
  79.  
  80. __fastcall TCap::TCap (HWND Handle)
  81. {
  82.     // create video capture window
  83.     ParentHandle = Handle;
  84.  
  85.      hwndVideo = capCreateCaptureWindow(
  86.                     (LPSTR) "0",
  87.                     WS_CHILD | WS_VISIBLE
  88.                     ,
  89.                      0, 0, 300, 200,
  90.                     (HWND) Handle,
  91.                     (int) 0);
  92.  
  93.  
  94.  
  95.     pStringCapDrivers = new TStringList;
  96.     SelectedDevice = -1;
  97. }
  98.  
  99.  
  100. __fastcall TCap::~TCap ()
  101. {
  102.  
  103.     delete pStringCapDrivers;
  104.  
  105.     capPreview(hwndVideo, FALSE); // end preview
  106.     capDriverConnect(hwndVideo, SelectedDevice);
  107.     capDriverDisconnect(hwndVideo); // disconnect from driver
  108. }
  109.  
  110. //---------------------------------------------------------------------------
  111. // enumerate the installed capture drivers
  112. //---------------------------------------------------------------------------
  113. int TCap::EnumCapDrv ()
  114. {
  115.   char szDeviceName[80]; // driver name
  116.   char szDeviceVersion[80]; // driver version
  117.   char str[161]; // concatinated string
  118.   int xcap; // counter
  119.  
  120.     xcap = 0;
  121.     pStringCapDrivers->Clear ();
  122.     do  {
  123.         if (capGetDriverDescription(xcap, szDeviceName, sizeof(szDeviceName),
  124.                   szDeviceVersion, sizeof(szDeviceVersion))){
  125.  
  126.             sprintf (str, "%s, %s", szDeviceName, szDeviceVersion);
  127.             pStringCapDrivers->AddObject (str, (TObject *)xcap);
  128.             }
  129.         else {
  130.             break;
  131.             }
  132.         xcap++;
  133.         } while (true);
  134.  
  135.     return 0;
  136. }
  137.  
  138. //---------------------------------------------------------------------------
  139. //  connecting to selected device and starts preview
  140. //---------------------------------------------------------------------------
  141. void TCap::Connect (int Selected)
  142. {
  143.     CAPSTATUS CapStatus;
  144.     int       hsize;
  145.       // capDlgVideoDisplay(hwndVideo);
  146.       // connect to the driver
  147.     if (SelectedDevice != -1) {
  148.         capPreview (hwndVideo, FALSE);
  149.         capDriverConnect(hwndVideo, SelectedDevice);
  150.         }
  151.  
  152.     if (!capDriverConnect(hwndVideo, Selected)) {
  153.         // ---- Unable to connect to driver
  154.  
  155.         return;
  156.         }
  157.  
  158.     // update the driver capabilities
  159.     capDriverGetCaps (hwndVideo, sizeof(CAPDRIVERCAPS), &CapDrvCaps);
  160.     capDlgVideoFormat(ParentHandle);
  161.     // Are there new image dimensions
  162.     capGetStatus(hwndVideo, &CapStatus, sizeof(CAPSTATUS));
  163.     hsize = GetSystemMetrics(SM_CYMENU);
  164.     hsize += GetSystemMetrics(SM_CYCAPTION);
  165.  
  166.     // ---- Rescaling the windows
  167.     SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth,
  168.                 CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
  169.     SetWindowPos(ParentHandle, NULL, 0, hsize, CapStatus.uiImageWidth,
  170.                 CapStatus.uiImageHeight+hsize, SWP_NOZORDER | SWP_NOMOVE);
  171.  
  172.  
  173.                         //  Cambiar formato de video a 320x240 24bits de color
  174.         // tambien podriamos ponerlo manualmente en esta
  175.         // resolución usando la función 'capDlgVideoFormat(w);'
  176.     BITMAPINFO bi;
  177.     ZeroMemory(&bi, sizeof(bi));
  178.     bi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
  179.     bi.bmiHeader.biWidth       = 320;
  180.     bi.bmiHeader.biHeight      = 240;
  181.     bi.bmiHeader.biPlanes      = 1;
  182.     bi.bmiHeader.biBitCount    = 24;
  183.     bi.bmiHeader.biCompression = BI_RGB;
  184.     if (!capSetVideoFormat(hwndVideo, &bi, sizeof(bi)))
  185.       throw Exception("No se puede cambiar el formato de video");
  186.         // Definimos la función que sera
  187.         // llamada antes de visualizar cada fotograma
  188.     if (!capSetCallbackOnFrame(hwndVideo, fcb))
  189.       throw Exception("callback no instalado");
  190.         // Previsualizar captura
  191.  
  192.     // set preview rate to 33.3 miliseconds, or 30 FPS
  193.     capPreviewRate (hwndVideo, 33.3);
  194.  
  195.     // start preview video
  196.     capPreview (hwndVideo, TRUE);
  197.  
  198.     // ---- Remember selected device
  199.     SelectedDevice = Selected;
  200.  
  201. }
  202.  
  203. //---------------------------------------------------------------------------
  204. //  Get access to the video source format box
  205. //---------------------------------------------------------------------------
  206. void TCap::Format ()
  207. {
  208.     int       hsize;
  209.  
  210.     CAPSTATUS CapStatus;
  211.  
  212.     capDlgVideoFormat(hwndVideo);
  213.     // Are there new image dimensions
  214.     capGetStatus(hwndVideo, &CapStatus, sizeof(CAPSTATUS));
  215.  
  216.     hsize = GetSystemMetrics(SM_CYMENU);
  217.     hsize += GetSystemMetrics(SM_CYCAPTION);
  218.  
  219.     SetWindowPos(ParentHandle, NULL, 0, hsize, CapStatus.uiImageWidth,
  220.                 CapStatus.uiImageHeight+hsize, SWP_NOZORDER | SWP_NOMOVE);
  221.     SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth,
  222.                 CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
  223. }
  224. //---------------------------------------------------------------------------
  225. //  Get access to the video source dialog box
  226. //---------------------------------------------------------------------------
  227. void TCap::Source ()
  228. {
  229.     capDlgVideoSource(hwndVideo);
  230. }
  231.  
  232. //---------------------------------------------------------------------------
  233. //  capture a frame and save it
  234. //---------------------------------------------------------------------------
  235. void TCap::CaptureFrame (char *FileName)
  236. {
  237.     capFileSaveDIB (hwndVideo, FileName);
  238. }
  239.  

archivo de cabecera

Código: Text
  1.  
  2. //---------------------------------------------------------------------------
  3.  
  4. //#ifndef c_capH
  5. //#define c_capH
  6. //---------------------------------------------------------------------------
  7. #include <vfw.h> // video for windows library
  8.  
  9. class TCap
  10. {
  11. private:
  12.  
  13. protected:
  14.     HWND ParentHandle;
  15.     HWND hwndVideo;
  16.     CAPDRIVERCAPS CapDrvCaps; // driver capabilities
  17.  
  18.     int     SelectedDevice;
  19.  
  20. public:
  21.     TStringList     *pStringCapDrivers;
  22.  
  23.     int EnumCapDrv();
  24.     void Connect (int Selected);
  25.     void Format ();
  26.     void Source ();
  27.     void CaptureFrame (char *FileName);
  28.   __fastcall TCap(HWND Handle);
  29.   __fastcall ~TCap();
  30.  
  31. };
  32.  
  33.  
  34. //#endif
  35.  
  36.  

ejemplo de funcionamiento:

Código: Text
  1.  
  2.  
  3. HWND w;
  4.  
  5.  w = capCreateCaptureWindow("Mi Video", WS_CHILD  ,
  6.                                1, 1, 320, 240, panelCaptura->Handle, 0);
  7.  
  8.    if (!w)
  9.         throw Exception("No se pudo seleccionar una ventana de captura");
  10.         // Se conecta con el primer dispositivo de captura que encuentra
  11.     bool bRet;
  12.     for (int iCapDrv=0; iCapDrv<10; iCapDrv++)
  13.     {
  14.         bRet = capDriverConnect(w, iCapDrv);
  15.         if (bRet) break;
  16.     }
  17.     if (!bRet)
  18.        {
  19.         Timer1->Enabled=false; // Desactivar Reloj
  20.         throw Exception("Error: no se encontraron dispositivos.");
  21.        }
  22.         // Mostramos en el titulo del form el nombre del driver seleccionado
  23.     char szNombreDrv[256];
  24.     /*
  25.     if ( capDriverGetName(w, szNombreDrv, sizeof(szNombreDrv)) )
  26.         Caption = szNombreDrv;
  27.       */
  28.         //  Cambiar formato de video a 320x240 24bits de color
  29.         // tambien podriamos ponerlo manualmente en esta
  30.         // resolución usando la función 'capDlgVideoFormat(w);'
  31.     BITMAPINFO bi;
  32.     ZeroMemory(&bi, sizeof(bi));
  33.     bi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
  34.     bi.bmiHeader.biWidth       = 320;
  35.     bi.bmiHeader.biHeight      = 240;
  36.     bi.bmiHeader.biPlanes      = 1;
  37.     bi.bmiHeader.biBitCount    = 24;
  38.     bi.bmiHeader.biCompression = BI_RGB;
  39.     if (!capSetVideoFormat(w, &bi, sizeof(bi)))
  40.       throw Exception("No se puede cambiar el formato de video");
  41.         // Definimos la función que sera
  42.         // llamada antes de visualizar cada fotograma
  43.     if (!capSetCallbackOnFrame(w, fcb))
  44.       throw Exception("callback no instalado");
  45.     capPreviewScale(w, false);
  46.     capPreviewRate(w, 1);
  47.  
  48.  
  49.  

ahora insercion de la funcion fcb que es llamada como el hook

Código: Text
  1.  
  2. LRESULT CALLBACK fcb(HWND w, LPVIDEOHDR h)
  3. {
  4.     BITMAPINFO bi;
  5.     ZeroMemory(&bi, sizeof(bi));
  6.     bi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
  7.     bi.bmiHeader.biWidth       = 320;
  8.     bi.bmiHeader.biHeight      = 240;
  9.     bi.bmiHeader.biPlanes      = 1;
  10.     bi.bmiHeader.biBitCount    = 24;
  11.     bi.bmiHeader.biCompression = BI_RGB;
  12.     std::auto_ptr<Graphics::TBitmap> bmp(new Graphics::TBitmap);
  13.     bmp->PixelFormat = pf24bit;
  14.     bmp->Width       = bi.bmiHeader.biWidth;
  15.     bmp->Height      = bi.bmiHeader.biHeight;
  16.     SetDIBits(bmp->Canvas->Handle, bmp->Handle, 0,
  17.         bi.bmiHeader.biHeight, h->lpData, &bi, DIB_RGB_COLORS);
  18.     std::auto_ptr<TJPEGImage> jpg(new TJPEGImage);
  19.     jpg->CompressionQuality = 50;
  20.     jpg->Assign(bmp.get());
  21.    // aqui esta elobjeto jpg, has con el lo que quieras
  22.  
  23.  
  24. return TRUE&#59;
  25. }
  26.