使用 openNi/NITE 从 Kinect 生成 jpeg 图像
我正在尝试将图像帧从 Kinect 生成传递给面部检测/跟踪算法。我已经看到从 openGL 纹理生成 jpeg 图像的最佳方法是通过 libjpeg 但我不知道如何开始。这就是我现在的代码:
//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);
那么我如何传递这个 g_pTexMap 东西以保存为 jpeg 图像?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OpenGL 不处理图像文件。如果您想将图像存储到文件中,将其传递给 OpenGL 并不是正确的做法。您不应将数据传递给 glTexImage2D,而应将其传递给 libjpeg 或其他图像文件访问库。
看看 imlib2 http://docs.enlightenment.org/api/imlib2/html/< /a>
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/
我确实尝试了 imlib2,但将 openNi XnRGB24Pixel 类型转换为 imlib2 正在寻找的数据流似乎很困难。 Imlib2 似乎更容易处理文件(例如 imageName.jpg)而不是内存中的数据流。然后我开始尝试 openCV,这是我从 openni 讨论页面 [链接] 获取和编辑的代码。
voidgenerateJpeg(const xn::ImageMetaData&g_imageMD){
I did try the imlib2 but it seemed difficult to convert openNi XnRGB24Pixel type to the data stream imlib2 is looking for. Imlib2 seems to work more easily with files (e.g imageName.jpg) rather than data streams in the memory. I then moved to try out openCV and here is the code I got and edited from an openni-discussion page [link here].
void generateJpeg(const xn::ImageMetaData& g_imageMD){