Andrea F
Andrea F

Reputation: 733

Loading image texture onto a CVWindow

I'm working in OpenCV and have a window that I want to add an image texture to. My code so far:

void display(void) {  
    GLuint texture[1];
    IplImage *image;

    image=cvLoadImage("Particle.png");

    if(!image){
        std::cout << "image empty" << std::endl;
    } else {
        glGenTextures(1, texture);
        glBindTexture(1,  GL_TEXTURE_2D );

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        // Set texture clamping method
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    }

    cvReleaseImage(&image);
}

int main(int argc, char**argv)
{
    display();
}

//window to draw the texture on
cvNamedWindow("video");

I'm new to OpenGL and find it confusing so any tips on how to improve it would be great or where to go from here (how to draw it on the window).

Upvotes: 0

Views: 118

Answers (1)

Aurelius
Aurelius

Reputation: 11359

Fortunately, you don't need to do any work in OpenGL to draw an image in a window: OpenCV provides this functionality already with the function cvShowImage().

Code to show the window might then be:

if(!image)
{
    std::cout << "image empty" << std::endl;
}
else
{
    cvNamedWindow("image");      // Create the window
    cvShowImage("image", image); // Display image in the window
    cvWaitKey();                 // Display window until a key is pressed
}

Upvotes: 1

Related Questions