March 18, 2004

Video for Windows with Borland C++ Builder

Obtaining USB camera snapshots using Video for Windows with Borland C++ Builder 5. It's just a very simple code. (I tested it with a Logitech QCam Messenger.)

1. Initialization is needed as usual.
2. Then execute capGrabFrameNoStop(hWndC).
3. A snapshot is given to your callback function.

A source code (fragment) below is displaying captured bitmap with DIBSection API. Still very simple. Use freely:)

char *lpData = 0;
int DataSize = 0;

LRESULT CALLBACK capVideoStreamCallback(
HWND hWnd,
LPVIDEOHDR lpVHdr
) {
CopyMemory(lpData,lpVHdr->lpData,lpVHdr->dwBufferLength);
return true;
}

__fastcall TQCam::TQCam(TComponent* Owner)
: TForm(Owner)
{
Width = 700;
Height = 550;

hWndC = capCreateCaptureWindow ( "My Own Capture Window",
WS_CHILD , 0, 0,320,160, Handle, 0xffff);
capDriverConnect(hWndC,0);
capPreview(hWndC,false);

WORD vfs = capGetVideoFormatSize(hWndC);
BITMAPINFOHEADER bmih;
bmih.biSize = sizeof(BITMAPINFOHEADER);
capGetVideoFormat(hWndC,&bmih,vfs);

PaintBox1->Width = bmih.biWidth;
PaintBox1->Height = bmih.biHeight;

hDIBSec = CreateDIBSection(0,(BITMAPINFO *) &bmih, DIB_RGB_COLORS,(void **)&lpData, NULL, 0);

capSetCallbackOnFrame(hWndC,capVideoStreamCallback);
}

__fastcall TQCam::~TQCam() {
capCaptureStop(hWndC);
capDriverDisconnect(hWndC);
}

void __fastcall TQCam::PaintBox1Paint(TObject *Sender)
{
TPaintBox *pb = (TPaintBox *) Sender;

HDC hdc = CreateCompatibleDC(0);
SelectObject(hdc,hDIBSec);
BitBlt(Canvas->Handle,0,0,pb->Width,pb->Height,
hdc,0,0,SRCCOPY);
DeleteDC(hdc);
}

void __fastcall TQCam::Timer1Timer(TObject *Sender)
{
PaintBox1->Repaint();
capGrabFrameNoStop(hWndC);
}


Posted by arai at March 18, 2004 02:32 AM
Comments

Hi
how could I change the saturation of the video picture?

Thanks Peter

Posted by: Peter on May 11, 2004 09:49 PM

Hi
I think you have to write a pixel modifying code to do that. It's not very easy task... Yet I imagine there are many books about it. Can someone recommend one?

Posted by: arai on May 12, 2004 03:11 AM

You can find a complete video/sound/text software using vfw and jpeg compression to send image using a network.

The program is YouAndMe :)

All in C++ using VC6 :)

Posted by: laurent weislo on June 4, 2004 06:06 PM

You can do it using capVideoStreamCallback and changing pixels in buffer lpData. First you should convert RGB to HSV and then change S.

Posted by: PSTV on January 24, 2006 03:59 AM

Video for Windows with Borland C++ Builder

Complete Project, can you send me please, i cant compile this code, maybe i don't have some include files in the project.

Thanks

Posted by: lfalves on June 3, 2006 02:10 AM
Post a comment














Please enter this 6digits Security Code (for SPAM's sake...).
spam対策のため6桁のセキュリティコードを入力してください。