Programación General > C++ Builder

 Aplicacion Con Camara

(1/1)

betitono1:
Hola que tal alguien podria de cirme como puedo hacer una aplicacion que me muestre lo que capta la camara que tiene la PC, como si fuera un chat.,

Saludos.

_Viktor:
Esto te servira ;)



--- Código: Text --- //--------------------------------------------------------------------------- /* * 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    
Saludos!

betitono1:
Hola gracias por la respuesta, esta aplicacion como la puedo hacer para que le envie el contenido que digitaliza la camaran hacia otra pc.

_Viktor:
Hola, este codigo que pongo a continuacion lo uso para enviar una imagen del escritorio de un pc a otro usando TServStrm y su respectivo cliente:


--- Código: Text ---  #include <memory>#include <jpeg.hpp> HDC dc = GetDC(0);Graphics::TCanvas *ScreenCanvas = new Graphics::TCanvas;ScreenCanvas->Handle = dc; std::auto_ptr<TJPEGImage>JImage(new TJPEGImage); Image1->Picture->Bitmap->Width = Screen->Width;Image1->Picture->Bitmap->Height= Screen->Height;TRect rect = Rect(0,0,Screen->Width, Screen->Height);Image1->Picture->Bitmap->Canvas->CopyRect(rect,   ScreenCanvas, rect);JImage->Assign(Image1->Picture->Graphic);JImage->CompressionQuality = 19;JImage->Compress(); std::auto_ptr<TMemoryStream> Stream(new  TMemoryStream); Jimage->SaveToStream(Stream.get()); Str->PostIt(Stream.get());   
Y esto para recibir:


--- Código: Text --- void __fastcall TForm1::StrmSerMSG(TComponent *Sender,       const AnsiString sFrom, TStream *strm) {     std::auto_ptr<TJPEGImage> JImage(new TJPEGImage);     JImage->LoadFromStream(strm);     Image1->Canvas->Draw(0, 0, JImage.get()); }    

Claro esto almacena la imagen en memoria en ningun momento se forma un archivo, si tu tienes que tomar la imagen desde un archivo solo tienes que modificar esto:


--- Código: Text --- std::auto_ptr<TMemoryStream> Stream(new  TMemoryStream); Jimage->SaveToStream(Stream.get());  Str->PostIt(Stream.get()); 
Por esto:

 
--- Código: Text ---TFileStream *MyFStream; MyFStream = new TFileStream("cap.jpg", fmOpenRead); Str->PostIt(MyFStream); MyFStream->Free(); 
Si tienes alguna duda, me avisa, vere que puedo hacer...  Esto facilmente lo puedes modificar para el codigo anterior.


Saludos

Navegación

[0] Índice de Mensajes

Ir a la versión completa