Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

projecting image with opengl and Antialiasing

In my work I overlap a part of a captured frame with an image. I open my webcam with openCV and then I transform the captured frame in a texture and display it in a GLUT window. Also, I overlap a part of this texture with this image:

enter image description here

I do this in real time, and the result is:

enter image description here

As you can see, edges of projected image are inaccurate. I think it is an aliasing problem, but I don't know how to do the antialiasing process with opengl. I've tried to look for on web, but I didn't find a good solution for my problem.

In my "calculate" function I transform the mat image into a texture usign the following code:

GLvoid calculate(){
...
...
cvtColor(image, image, CV_BGR2RGB);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glBindTexture(GL_TEXTURE_2D, textures[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    //glTexImage2D(GL_TEXTURE_2D, 0, 4,image.cols, image.rows, 0, GL_RGB,GL_UNSIGNED_BYTE, image.data);
    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.cols, image.rows, GL_RGB, GL_UNSIGNED_BYTE, image.data);
}

and I show the result using this code:

GLvoid Show(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);

    // Matrice di proiezione
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, WIDTH, HEIGHT, 0); 

    // Matrice model view
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity(); 
...
...
glBindTexture(GL_TEXTURE_2D, textures[1]);
        glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f); glVertex2f((GLfloat)((coord[3].x)),(GLfloat)(coord[3].y));
        glTexCoord2f(1.0f, 0.0f); glVertex2f((GLfloat)((coord[0].x)),(GLfloat)(coord[0].y));
        glTexCoord2f(1.0f, 1.0f); glVertex2f((GLfloat)((coord[1].x)),(GLfloat)(coord[1].y));
        glTexCoord2f(0.0f, 1.0f); glVertex2f((GLfloat)((coord[2].x)),(GLfloat)(coord[2].y)); 

        glEnd();    
    }
    glFlush();
    glutSwapBuffers();

}

In initialization function I write this:

GLvoid Init() {  

    glGenTextures(2, textures);
    glClearColor (0.0, 0.0, 0.0, 0.0);

    glEnable (GL_POLYGON_SMOOTH);
    glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);
    glDisable(GL_DEPTH_TEST);

}

but it doesn't work...

I work on Win7 x64, with OPenGL 4.0 and Glut 3.7. My video card is an NVidia GeForce gt 630. also I enabled antialiasing from Nvidia control panel, but nothing is changed. does anyone know how to help me?

like image 761
Cristina1986 Avatar asked Apr 02 '13 12:04

Cristina1986


1 Answers

I solved my problem! I used GLFW insted of GLUT, as @Michael IV suggested me!

in order to do antialiasing with GLFW i used this line of code:

glfwOpenWindowHint(GLFW_FSAA_SAMPLES,4);

and the result now is very good, as you can see in the following image.

enter image description here

Thanks for your help!

like image 196
Cristina1986 Avatar answered Oct 29 '22 18:10

Cristina1986