Convert rgba image to rgb

Hi! I’m trying to convert a RGBA image to RGB i use to use this algorightm :

      photo.setFromPixels(camera.getPixelsRef());
     unsigned char * photoCvPix = photoCV.getPixels();
     unsigned char * photoPix = photo.getPixels();   
    
    for (int i = 0; i < capW * capH; i++){
        photoCvPix[ i * 3 + 0] = photoPix[i*nChannels + 0];
        photoCvPix[ i * 3 + 1] = photoPix[i*nChannels + 1];
        photoCvPix[ i * 3 + 2] = photoPix[i*nChannels + 2];

}

  photoCV.flagImageChanged(); 

But now i try it and i got this errors:

Any idea?

i’m sure you can use openCv for that.

cv::cvtColor(srcRgba , src , CV_RGBA2RGB);

Do i need to add library or somthing to make it work?

You need to add addon ofxOpenCv (use projectGenerator to import project and add addon) and add in file #include ofxOpenCv.h in the header file from class you going to use it.

and/or use ofxCv addon

I’m using opencv actually but is no recognizing the code:

Yeah,i’m acually using opencv.

Did you try ofPixels methods? I thought that was as easy as setImageType(OF_IMAGE_COLOR).
Please check that out! You don’t need opencv for that operation only.

1 Like

look at the ofxCv examples how the convert ofImages and ofPixels to cv::Mat so that openCv can use them. something like toCv(myOfImage)