OpenCv chromakey / color removal

I’ve also posted a thread in the “beginner” forum, but as it is related to OpenCv, I’d like to stick a mention in here as well. The other thread is here http://forum.openframeworks.cc/t/chromakeycolor-replacementgreen-screeningetc./2308/0

I’m trying to accomplish some simple green screen removal using OpenCV to process a single image (not a video feed). I’m sure this is very easy, but as I’m kind of a newbie to this stuff, I am likely overlooking something simple and stupid.

The problem I’m having is that the image this draws is now solid black. I’m no longer seeing “OF_ERROR: image data too big for allocated texture. not uploading…” as I mentioned in the other thread.

The problem seems to happen somewhere during or after I loop through the pixels, mark them, and try to dump the results into a texture.

Can anybody smarter than I am help out? What in the world am I doing wrong?

Thanks all :slight_smile:

  
  
#include "GreenRemove.h"  
  
void GreenRemove::setup()  
{  
    imgDrawHeight = 800;  
    imgDrawWidth = 525;  
     
    grn.hue = 154;  //hue mid-range  
    grn.huerange = 5;   // hue range +/-  
    grn.sat = 95;  //sat mid-range  
    grn.satrange = 5;   // sat range +/-  
  
    img.setUseTexture(false);  
    img.loadImage("images/IMG_0017.JPG");  
  
    imgWidth = img.getWidth();  
    imgHeight = img.getHeight();  
  
    colorImg.allocate(imgWidth,imgHeight);  
  
    hueImg.allocate(imgWidth,imgHeight);   //hue map  
    satImg.allocate(imgWidth,imgHeight);   //saturation map  
    briImg.allocate(imgWidth,imgHeight);   //brightness map, not used, necessary  
  
    colorTrackedPixelsGreen = new unsigned char [imgWidth * imgHeight * 3];     //rangeImage  
    trackedTextureGreen.allocate(imgWidth,imgHeight, GL_RGB);        //final output  
  
    descreen_color_image(&img);  
}  
  
void GreenRemove::descreen_color_image(ofImage* im) {  
  
    colorImg.setFromPixels(im->getPixels(), imgHeight, imgWidth);  
    colorImg.convertRgbToHsv();  
    colorImg.convertToGrayscalePlanarImages(hueImg, satImg, briImg);       
  
    unsigned char * huePixels = hueImg.getPixels();  
    unsigned char * satPixels = satImg.getPixels();  
  
    for (int i = 0; i < im->imgWidth * im->imgHeight; i++){      //loop through all the pixels  
        int base = i * 3;   //3 bits per pixel  
        
      //if hue is in range and if saturation is in range  
        if ((huePixels[i] >= grn.hue - grn.huerange && huePixels[i] <= grn.hue + grn.huerange) &&     
            (satPixels[i] >= grn.sat - grn.satrange && satPixels[i] <= grn.sat + grn.satrange)){     
            //mark this pixel white  
         colorTrackedPixelsGreen[base + 0] = 255;  
            colorTrackedPixelsGreen[base + 1] = 255;  
            colorTrackedPixelsGreen[base + 2] = 255;  
        } else {  
         //if not, mark the pixel black  
            colorTrackedPixelsGreen[base + 0] = 0;  
            colorTrackedPixelsGreen[base + 1] = 0;  
            colorTrackedPixelsGreen[base + 2] = 0;  
        }  
    }  
  
    trackedTextureGreen.loadData(colorTrackedPixelsGreen, imgWidth, imgHeight, GL_RGB);   
}  
  
void GreenRemove::draw()  
{  
    ofPushMatrix();  
    ofTranslate(100,100,0); //move  
    ofRotateZ(90);  //rotate  
  
    trackedTextureGreen.draw(-90, -500, imgDrawHeight, imgDrawWidth);  
  
    ofPopMatrix();  
}  
  

Hi,

Did you get it working?

Thanks.

Eduardo