Create and R-G Plane image from ofxCvColorImage

so yeah basically i’m looking on how to create this R-G 2 channel image, i know i can use cvSplit() to break up a RGB image into its R, G, B planes and then use cvMerge() to create the R-G image holder that is of 2 channels i’m trying to specifically do skin detection using the following formula:

(R,G,B) is classi?ed as skin if:
R > 50 and G > 20 and
R ? G < 100 and R ? B < 160 and G ? B < 75
and R > G and R > B

I think what you want to do is convert an image to HSV space and then use a method like cvInRangeS() to createa binary image that’s white where your color is found and black everywhere else. From that you can just use findContours() to get all the blobs in the image. There’s a stackoverflow post on this here:

http://stackoverflow.com/questions/9073124/hsv-colour-space-and-cvinranges-function

You are referring to HSV colour-space, based skin segmentation, i actually have that implemented and i also have YCbCr colour-space, based skin segmentation also. what i need to do is implement RGB colour-space, based skin segmentation. The union of all 3 will give me better results than just having the one colour space or the union of 2 of the colour spaces.

i know you can create IplImage with 2 channels with the following line

IplImage* RG = cvCreateImage(cvGetSize(colorImg.getCvImage()), 8, 2);

but what ive found is that this line crashes the application when you use it with videoGrabber. It works fine on an image.

Ah, I misunderstood. You want to use the ofxCvImage if you want something more convenient, that has a method which returns the IplImage* it contains with getCvImage(), and you can allocate it with cvCreateImage() like you’re doing below. To copy the pixels from a vidGrabber into the IplImage* something like this should work:

  
  
        ofPixels pix = vidGrabber.getPixelsRef(); // not optimised at all, more for clarity.  
        int i = 0;  
        while( i < 320 * 240) {  
            RG->imageData[i*2] = pix[i*3];  
            RG->imageData[i*2 + 1] = pix[i*3 + 1];  
            i++;  
        }