I am trying to generate pass the image frames to a face-detection/tracking algorithm from the Kinect. I’ve seen that the best way to generate jpeg images from openGL textures is via libjpeg but I’m clueless on how to start. This is what I have on my code now:
//draw image frame to texture
const XnRGB24Pixel* pImageRow = g_imageMD.RGB24Data();
XnRGB24Pixel* pTexRow = g_pTexMap + g_imageMD.YOffset() * g_nTexMapX;
for (XnUInt y = 0; y < g_imageMD.YRes(); ++y)
{
const XnRGB24Pixel* pImage = pImageRow;
XnRGB24Pixel* pTex = pTexRow + g_imageMD.XOffset();
for (XnUInt x = 0; x < g_imageMD.XRes(); ++x, ++pImage, ++pTex)
{
*pTex = *pImage;
}
pImageRow += g_imageMD.XRes();
pTexRow += g_nTexMapX;
}
// Create the OpenGL texture map
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_nTexMapX, g_nTexMapY, 0, GL_RGB, GL_UNSIGNED_BYTE, g_pTexMap);
So how can I pass on this g_pTexMap thing to be saved as a jpeg image?
OpenGL does not deal with image files. If you want to store an image to a file, passing it to OpenGL is not doing the right thing to do. Instead of passing the data to glTexImage2D you should pass it to libjpeg or another image file access library.
Have a look at imlib2 http://docs.enlightenment.org/api/imlib2/html/