使用 openNi/NITE 从 Kinect 生成 jpeg 图像

发布于 2024-11-16 16:30:28 字数 1083 浏览 2 评论 0原文

我正在尝试将图像帧从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2024-11-23 16:30:28

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/

故事↓在人 2024-11-23 16:30:28

我确实尝试了 imlib2,但将 openNi XnRGB24Pixel 类型转换为 imlib2 正在寻找的数据流似乎很困难。 Imlib2 似乎更容易处理文件(例如 imageName.jpg)而不是内存中的数据流。然后我开始尝试 openCV,这是我从 openni 讨论页面 [链接] 获取和编辑的代码。

voidgenerateJpeg(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);

}

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){

    //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);

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文