CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2006
    Posts
    7

    Question 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;
    }

  2. #2
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    324

    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.....]
    }
    Regards,
    Marco Era
    www.marcoera.com

    Latest post on my blog: Back to the Amiga's times

  3. #3
    Join Date
    May 2006
    Posts
    7

    Question 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.

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5
    Join Date
    May 2006
    Posts
    7

    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 ).

  6. #6
    Join Date
    May 2005
    Posts
    4,954

    Re: Webcam Image Manipulation

    You are welcome

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured