Edge Around Texture ofFBO

I’m having an ‘outline’ edge issue using a CV image as a mask (from a kinect).
Below are a few pictures, I’m sure this must be a known fix but my OF/GL knowledge is far from excellent.
Any help would be really helpful. I’ve been really struggling with these textures!



//----------------------------------------------------------------------------------------------------------------------------------------------------------------
void Kinect::update(){

kinect.update();
if(kinect.isFrameNew()) {
    grayImage.setFromPixels(kinect.getDepthPixels());
    grayThreshNear = grayImage;
    grayThreshFar = grayImage;
    grayThreshNear.threshold(nearThreshold, true);
    grayThreshFar.threshold(farThreshold);
    cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);
    grayImage.flagImageChanged();

}

}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------
mask.begin(); // To strech kinect image across width/height
ofClear(255, 255, 255, 255);
kinect.grayImage.draw(0, 0, ofGetWidth(), ofGetHeight());
mask.end();
_mask.setSwizzle(GL_TEXTURE_SWIZZLE_A, GL_RED);
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
ofDisableSmoothing();
tex.setAlphaMask(_mask);
tex.draw(0, 0, ofGetWidth(), ofGetHeight());
//_mask.draw(0, 0, ofGetWidth(), ofGetHeight());

seems like an alpha problem. I remember that there was a similar topic answered long ago. @zach might know.
Besides this, have you tried using a higher bit count for your FBO?
Allocate like this instead:

fbo.allocate(width, height, GL_RGBA32F_ARB);

hope this helps

Thanks for you reply Roy! I’ve just tried:

fbo.allocate(width, height, GL_RGBA32F_ARB);

but with no luck unfortunately, still getting the line around the edge of the depth image. I’ll try different formats. Thank you for the suggestion!

I made a hacky work around, but feels awfully inefficient?

convert to pixels, resize using NN, make image draw in FBO.

mask.begin();       //  To strech kinect image across width/height
ofPixels _pix = kinect.grayImage.getPixels();
_pix.resize(mask.getWidth(), mask.getHeight(), OF_INTERPOLATE_NEAREST_NEIGHBOR);
ofImage _image;
_image.setFromPixels(_pix);
_image.draw(0, 0, mask.getWidth(), mask.getHeight());
mask.end();

yes, that looks really inefficient. :slight_smile:

can you save one of those kinect mask images that generate this problem and upload it please? make sure you save as TIFF, so it has its alpha channel and no compression.

Thank you for pursuing this :slight_smile:,
If I’m honest I’m not too sure how best to get a copy of this kinect frame, it is coming straight out of the Kinect and I’m pushing it through some ofxOpenCV processing like in the ofxKinect example.

To create the mask I’m getting the texture from a “GL_RGBA” alocated FBO and using the texture from another FBO and calling:

tex.setAlphaMask(_mask);

I initially thought the issue was in the upscaling of the texture inside the FBO as I was calling the ofxGrayScaleImage .draw to fill the mask FBO.

This appears to be where it’s going wrong as I now, converting t to ofPixels and resizing the image by using OF_INTERPOLATE_NEAREST_NEIGHBOR, the unwanted edge disappears.

Again, I certainly don’t know OF as well as you so my approach might be completely wrong and I’m just seeing a quick result from a dirty fix.

How would it be best to get this image?

Thanks again, you have helped me on many a project!

Hi,
can you post the code of it please, make sure you do so by pasting it here, selecting the code and pressing the </> button, instead of uploading files.?

It makes sense that you’ve got those edges if you were upscaling and then using that as a mask. just as a hint, most of the times when you do CV stuff upscaling just adds computational cost and not much benefits.