Webcam Image Manipulation
Greetings.
I have modified the code from the Simultaneous Previewing & Video Capture using DirectShow written by Sivasagar K.R in www.codeguru.com (see below). When I run it, it uses the *ptr pointer to render the pixels on screen, but I want to analyse the pixels for each frame, rendering the analysed pixels.
In essence, I want to save the pixels (as I do in the array CurImaArr) and then do some analysis on them, maybe change some values, and then render them. Any ideas on how to do so?
Your help would be very much appreciated.
bool CVMR_Capture::Convert24Image(BYTE *p32Img, BYTE *p24Img,DWORD dwSize32)
{
if(p32Img != NULL && p24Img != NULL && dwSize32>0)
{
DWORD dwSize24;
dwSize24=(dwSize32 * 3)/4;
BYTE *pTemp,*ptr;
//pTemp=p32Img + sizeof(BITMAPINFOHEADER); ;
pTemp=p32Img;
ptr=p24Img + dwSize24-1 ;
int ival = 0;
int count = 0;
int witth = 1;
int hite = 0;
int hites = 120;
int greens = 0;
for (DWORD index = 0; index < dwSize32/4 ; index++)
{
unsigned char r = *(pTemp++);
unsigned char g = *(pTemp++);
unsigned char b = *(pTemp++);
(pTemp++);//skip alpha
if ((witth <= 320) && (hite < 240))
{
CurImaArr [witth-1][hite] = g;
}
else
{
return false;
}
if (g > 150)
{
greens++;
}
*(ptr--)= 0; //blue
*(ptr--)= CurImaArr [witth-1][hite]; //g; //green
*(ptr--)= 0; //yellow
witth++;
if (witth >= 320)
{
witth = 1;
hite++;
}
}
}
else
{
return false;
}
return true;
}
Re: Webcam Image Manipulation
In the code you've shown, a variable for the three color components (RGB) of each pixel is initialized. You can modify values here, before they're added to the CurImaArr array (which is probably used for rendering).
for (DWORD index = 0; index < dwSize32/4 ; index++)
{
unsigned char r = *(pTemp++);
unsigned char g = *(pTemp++);
unsigned char b = *(pTemp++);
[..... modify r, g, b here.....]
}
Re: Webcam Image Manipulation
Thanks puzzolino.
Actually, CurImaArr was added by me. My question was how to render the image after I have gotten all the pixels of the image, outside the "for" loop.
Ideally I would like some pointers (no pun intended) on how to make a new function that would use the array to render the image (or a new image on the screen) and on how to save the image on file.
I am looking in books and online, but any help would be appreciated as a lot of the stuff I read is beyond my current knowledge.
Again, thanks for the reply.
Re: Webcam Image Manipulation
Quote:
Originally Posted by Onthepath
Thanks puzzolino.
Actually, CurImaArr was added by me. My question was how to render the image after I have gotten all the pixels of the image, outside the "for" loop.
Ideally I would like some pointers (no pun intended) on how to make a new function that would use the array to render the image (or a new image on the screen) and on how to save the image on file.
I am looking in books and online, but any help would be appreciated as a lot of the stuff I read is beyond my current knowledge.
Again, thanks for the reply.
Look at those threads:
Cheers
Re: Webcam Image Manipulation
golanshahar, thanks. This was very useful. I'll post again when I 've played around with it a little bit (=more questions coming :) ).
Re: Webcam Image Manipulation
You are welcome :wave:
Cheers