我正在尝试从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图像呢?
发布于 2011-06-21 01:58:20
OpenGL不处理图像文件。如果您想要将图像存储到文件中,将其传递给OpenGL并不是正确的做法。您应该将数据传递给libjpeg或其他图像文件访问库,而不是将数据传递给glTexImage2D。
看一看imlib2 http://docs.enlightenment.org/api/imlib2/html/
发布于 2011-06-21 12:17:05
我确实尝试过imlib2,但似乎很难将openNi XnRGB24Pixel类型转换为imlib2要查找的数据流。与内存中的数据流相比,Imlib2似乎更容易处理文件(例如imageName.jpg)。然后我开始试用openCV,下面是我从一个开放讨论页面链接中获得并编辑的代码。
void generateJpeg(const xn::ImageMetaData& g_imageMD){
//opencv to convert image to jpeg
printf("Converting image to jpeg.\n");
cv::Mat colorArr[3];
cv::Mat colorImage;
const XnRGB24Pixel* pPixel;
const XnRGB24Pixel* pImageRow;
pImageRow = g_imageMD.RGB24Data();
colorArr[0] = cv::Mat(g_imageMD.YRes(),g_imageMD.XRes(),CV_8U);
colorArr[1] = cv::Mat(g_imageMD.YRes(),g_imageMD.XRes(),CV_8U);
colorArr[2] = cv::Mat(g_imageMD.YRes(),g_imageMD.XRes(),CV_8U);
for (int y=0; y<g_imageMD.YRes(); y++){
pPixel = pImageRow;
uchar* Bptr = colorArr[0].ptr<uchar>(y);
uchar* Gptr = colorArr[1].ptr<uchar>(y);
uchar* Rptr = colorArr[2].ptr<uchar>(y);
for(int x=0;x<g_imageMD.XRes();++x , ++pPixel){
Bptr[x] = pPixel->nBlue;
Gptr[x] = pPixel->nGreen;
Rptr[x] = pPixel->nRed;
}
pImageRow += g_imageMD.XRes();
}
cv::merge(colorArr,3,colorImage);
IplImage bgrIpl = colorImage;
cvSaveImage("image.jpg",&bgrIpl);
}https://stackoverflow.com/questions/6415257
复制相似问题