开发者

16u Channel to 8u Channel for OpenCV Blob tracking

Can anyone tell my why this doesnt work?

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

Writing the image out to disk works fine. Trying to use the channel as data OR AS A CINDER GL_TEXTURE does NOT work. Simply put, the values are being written into the channel (i believe) and yet for whatever reason, only 1 contour is found when i blob track and the texture comes out totally black.

I've tried bit shifting and also printing out the values as opposed to converting to 开发者_Python百科float and many other methods and it always results in a black texture on the screen and only 1 contour found.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜