Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

LUMINANCE doesn't work for Textures #52

Closed
ghost opened this issue Jul 23, 2014 · 2 comments
Closed

LUMINANCE doesn't work for Textures #52

ghost opened this issue Jul 23, 2014 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 23, 2014

For kinect (specifically) but in general:

If you have a LUMINANCE array ( say, from the depth camera ) that comes in as 16bits per pixel, you can store that in an ofShortPixels.

and later, load this into a texture like this:

depthTex.loadData(depthPixels.getPixels(), depthFrameDescription.width, depthFrameDescription.height, GL_LUMINANCE);

However in RT, Textures defined as GL_LUMINANCE fail to display properly.

Is this maybe an Angle thing? Or can we write up a workaround for RT?

Trying to get an ofxKinectV2RT helper class going for this weekend hackfest, thanks...

@stammen
Copy link

stammen commented Jul 23, 2014

Try GL_RED.

Look at openframeworks#2952

@ghost
Copy link
Author

ghost commented Jul 24, 2014

So, GL_RED didn't work, but I got GL_LUMINANCE to work by massaging the data better. Closing the issue.

Here is the combo that ended up working and displaying (partial code from the KinectV2 Helper class I'm writing):

ofTexture& getDepthFrameAsTexture(DepthFrame^ depthFrame)
{
if ( !depthFrameArray.isAllocated() ) {
_depthFrameArray = ref new Platform::Array(depthFrame->FrameDescription->LengthInPixels);
}

if ( _depthFramePixels.isAllocated() ) {
    _depthFramePixels.allocate(
        depthFrame->FrameDescription->Width,
        depthFrame->FrameDescription->Height,
        OF_IMAGE_GRAYSCALE);
}

// STORE THE DEPTH FRAME INTO AN ARRAY
depthFrame->CopyFrameDataToArray(_depthFrameArray);

// IF YOU WANT TO CONVERT THE ARRAY INTO AN ofPixels, DO THIS:
for (int i = 0; i < _depthFrameArray->Length; i++)
{
    _depthFramePixels.getPixels()[i] = depthValueToGreyscaleTable[
                ofClamp(_depthFrameArray[i], 
                0, 
                depthValueToGreyscaleTable.size() - 1)];
}

// AND TO CONVERT THE ofPixels INTO A TEXTURE, DO THIS:
if (!_depthFrameTexture.isAllocated())
{
    _depthFrameTexture.allocate(
        depthFrame->FrameDescription->Width,
        depthFrame->FrameDescription->Height,
        GL_LUMINANCE
        );
}

_depthFrameTexture.loadData(tempPixels);
return _depthFrameTexture;

}

// HERE IS THE LOOKUP TABLE THAT CONVERTS THE UINT16 DEPTH VALUE IN MM TO A MAPPED CHAR FOR GREYSCALE
void ofxKinectV2RT::updateDepthValueToGreyscaleTable()
{
unsigned char nearColor = 255;
unsigned char farColor = 0;
unsigned int maxDepthLevels = 5001;
depthValueToGreyscaleTable.resize(maxDepthLevels);
depthValueToGreyscaleTable[0] = 0;
for (unsigned int i = 1; i < maxDepthLevels; i++)
{
depthValueToGreyscaleTable[i] = ofMap(i, 500, 4000, nearColor, farColor, true);
}
}

@ghost ghost closed this as completed Jul 24, 2014
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant