Advertisement

05.07.2008 at 11:18AM PDT, ID: 23383736
[x]
Attachment Details

accessing frame grab pixels  webcam, vc++

Asked by leevonk in Microsoft Visual C++.Net, Windows MFC Programming, Microsoft Visual C++

Tags: microsoft, vc++, 6.0

can I access the pixels of a frame grabbed via capGrabFrame() _without_ saving it as a bitmap to the hardrive? The reason for this is that I'm trying to make a color tracking program. I want to be able to wave a light in front of the webcam and have real time tracking of it (in the dark, light will be only light). I figure that saving each frame as a bmp file and then opening it and checking for the color would be very slow.

The code I'm using is below, I'm not sure if it is correct. I keep getting the value 4294967295 returned from GetPixel, no matter where the camera points. I think that may be an error value...

this is my code so far:
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
//in the initialization function:
//-------------------------------------
hWndC = capCreateCaptureWindow ( "Capture Window", WS_CHILD |WS_DLGFRAME , 50, 50,320,240,GetSafeHwnd(), 11011);
 
 
  if(hWndC)
     capDriverConnect (hWndC, 0); // 0 ->means default driver.
  else
  {
     AfxMessageBox("Error Cammera is not connected!");
     exit(1);
  }
//--------------------------------------
 
void CVidtestDlg::OnOK() 
{
HDC hdc;
int X = 1;
int Y = 1;
unsigned long RGB; 
 
//grab a framefrom webcam, save it as a bmp file for confirmation of successful grab
capGrabFrame(hWndC);
capFileSaveDIB(hWndC,"MyFrameGrab_HelloWorld.bmp");
 
//get device context
hdc = ::GetDC(hWndC);
 
//get a pixel from the fram grab...?
RGB = GetPixel(hdc, X, Y);
 
//send RGB to a file so I can see what it is
ofstream fout;
fout.open("PixelData.dat", ios::app);
fout << RGB << endl;		
fout.close( );
 
/* 
//try to break up RGB assuming it's a 32-bit double word
red = ((0x00FF0000 & RGB) >> 16) << 0;
green = ((0x0000FF00 & RGB) >> 8) << 0;
blue = ((0x000000FF & RGB) >> 0) << 0; 
//show the pixel value in my GUI dialog
m_RGB = red;
m_RGB2 = green;
m_RGB3 = blue;
UpdateData(FALSE);
*/
}
 
 
Loading Advertisement...
 
[+][-]05.08.2008 at 12:20AM PDT, ID: 21522887

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 05:41AM PDT, ID: 21524114

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 02:03AM PDT, ID: 21562219

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C++.Net, Windows MFC Programming, Microsoft Visual C++
Tags: microsoft, vc++, 6.0
Sign Up Now!
Solution Provided By: DanRollins
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.11.2008 at 06:16PM PDT, ID: 21987168

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 05:49PM PDT, ID: 21990908

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.16.2008 at 08:25PM PDT, ID: 22022119

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628