Set pixel in ofxCvGrayscaleImage

Hey all. I’m thinning a binary image from video. I’m not sure if I’m reading/writing this correctly. The code below compiles/runs fine, but you can see my wacky attempt to convert uint to char. Basically, I need to be able to tell if a pixel is black or white, and also set it to black or white.

  
// Iterate through image rows  
for (int y = 0; y < __captureHeight; y++)  
{  
  
    // Iterate through columns  
    for (int x = 0; x < __captureWidth; x++)  
    {  
  
        // Find black pixel (on)  
        if (__greyDiff.getCvImage()->imageData[y * __captureWidth + x] == (char)0x00)  
        {  
  
            // Start counting black pixels  
            int onCount = 0;  
            while (__greyDiff.getCvImage()->imageData[y * __captureWidth + x] == (char)0x00)  
            {  
  
                // Turn pixel off  
                __greyDiff.getCvImage()->imageData[y * __captureWidth + x] = (char)0xFF;  
  
                // Increase count and position  
                onCount++;  
                x++;  
  
            }  
  
            // Turn on pixel in middle of run  
            __greyDiff.getCvImage()->imageData[y * __captureWidth + CLAMP(y * __captureWidth + (x - (int)((float)onCount / 2.0f)), 0, __captureWidth - 1)] = (char)0x00;  
  
        }  
  
    }  
  
}  

a quick way to access IplImage or CvMat data woul be using cvGet2D and cvSet2D.

Awesome, thanks!

I also realized that I’m casting to char and not unsigned char, which would explain why I’m turning every pixel white. in that routine.

Will try this out, though, since it’s less hacky.