用于OpenCV Blob跟踪的16u通道至8u通道

时间:2010-12-13 16:55:21

标签: opengl opencv

有谁可以告诉我为什么这不起作用?

void CVBlobTrack::updateKinect(ImageSourceRef kdepth, ImageSourceRef kcolor) {
cv::Mat input;
cv::Mat output;

channel16 = Channel16u(kdepth);



// Conversion from 16 bit int to 8 bit int for blob track

//uint16_t *largeImage = (uint16_t *)channel16.getData();
//uint8_t *smallImage = (uint8_t *)channel8.getData();

for (int y = 0; y < 480; y++)
{
    for (int x = 0; x < 640; x++)
    {
        uint8_t c = floor(float(channel16.getValue(Vec2i(x,y))) / 65545.0f * 255.0f );                         

        // This needs to change as its slooooooooooow
        channel8.setValue(Vec2i(x,y), c);

    }
}


writeImage("test", channel8, "png");

cvSetData(mKinectDepthImage8, channel8.getData(), mKinectDepthImage8->widthStep);

将图像写入磁盘工作正常。尝试将通道用作数据或作为CINDER GL_TEXTURE不起作用。简单地说,这些值被写入通道(我相信),但无论出于何种原因,当我blob轨道并且纹理完全​​变黑时,只能找到1个轮廓。

我已经尝试了位移和打印出值而不是转换为浮点和许多其他方法,它总是在屏幕上产生黑色纹理,只找到1个轮廓。

void CVBlobTrack::draw() {
if(channel8) {
    gl::Texture ttex = gl::Texture(channel8);
    glEnable(GL_TEXTURE_2D);
    ttex.bind();
    glBegin(GL_QUADS);
    gl::color(Color::white());

    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, 0.0f,0.0f);

    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(640.0f, 0.0f,0.0f);

    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(640.0f, 480.0f ,0.0f);

    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, 480.0f,0.0f);
    glEnd();

    ttex.unbind();
    glDisable(GL_TEXTURE_2D);
}

}

0 个答案:

没有答案