Problem with the projection coordinate

Hey,

I am working on a project using Nuitrack SDK. The project is similar to a smart mirror, so I have to draw the 640x480 camera output to an 2160x4096.

To do that I use glOrtho function and I crop the texture coordinate in width in order to fill the entire display and also keep proportionality.

The problem is when I crop the texture, the project coordinate are wrong in width. In height everything is good but in width the arms are on the chest for example.

I used the opengl sample code provided within the SDK. The problem should come from these lines :

// Helper function to draw a skeleton bone
void NuitrackRenderHandler::drawBone(const Joint& j1, const Joint& j2)
{
    // Prepare line data for confident enough bones only
    if (j1.confidence > 0.15 && j2.confidence > 0.15)
    {
        _lines.push_back(_displayWidth * j1.proj.x);
        _lines.push_back(_displayHeight * j1.proj.y);
        _lines.push_back(_displayWidth * j2.proj.x);
        _lines.push_back(_displayHeight * j2.proj.y);
    }
}

I replaced _width and _height (respectively 640 and 480) by the display’s size (2160x4096).
Is there any conversion to do with the joint’s coordinates because of the scaling ?

Here is the initTexture function with the scaling (glOrtho is called in the main loop) :

void NuitrackRenderHandler::initTexture(int width, int height)
{
GLfloat scale = (GLfloat)_displayHeight / (GLfloat)_height; // <- using this scale will guarantee the height of the new image is the same as the display's height but might crop the width
GLfloat scaledWidth  = _width * scale;
GLfloat widthDifference  = scaledWidth - _displayWidth;
GLfloat percentage = (widthDifference / scaledWidth)/2;

glGenTextures(1, &_textureID);

if (_textureBuffer != 0)
    delete[] _textureBuffer;

_textureBuffer = new uint8_t[width * height * 3];
memset(_textureBuffer, 0, sizeof(uint8_t) * width * height * 3);

glBindTexture(GL_TEXTURE_2D, _textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


// Set texture coordinates [0, 1] and vertexes position
{
    _textureCoords[0] = 1.0 - percentage;
    _textureCoords[1] = 1.0;

    _textureCoords[2] = 1.0 - percentage;
    _textureCoords[3] = 0.0;

    _textureCoords[4] = percentage;
    _textureCoords[5] = 0.0;

    _textureCoords[6] = percentage;
    _textureCoords[7] = 1.0;

    _vertexes[0] = _displayWidth;
    _vertexes[1] = _displayHeight;

    _vertexes[2] = _displayWidth;
    _vertexes[3] = 0.0;

    _vertexes[4] = 0.0;
    _vertexes[5] = 0.0;

    _vertexes[6] = 0.0;
    _vertexes[7] = _displayHeight;
}
}

Thanks you in advance

Hi Alexandre,

Please send us the screenshots illustrating the problem: