Ziri
November 7, 2023, 1:15am
1
Is there any minimal example of displaying and image , rectangle , text using :
cv::namedWindow(DISPLAY_WINDOW_NAME, cv::WINDOW_OPENGL);
I was able to display an image using this callback function :
void on_image_update_clbk(void* param) {
/*draw image */
cv::ogl::Texture2D* backgroundTex = (cv::ogl::Texture2D*)param;
glEnable(GL_TEXTURE_2D);
backgroundTex->bind();
cv::ogl::render(*backgroundTex);
glDisable(GL_TEXTURE_2D);
}
but I wasn’t successful until now to draw a text and rectangle on the top of that display.
I don’t know OpenCV’s OpenGL facilities well enough to help here.
OpenCV’s GUI facilities are limited in general.
I don’t know if there are ways to draw OpenGL primitives into such a window/viewport on top of the texture.
you can probably imagine that drawing into the Mat with cv::putText()
and cv::rectangle()
is an option.
you might be better served by using something like GLUT or GLFW and issuing your own OpenGL calls, combined with turning your image into a texture of some kind. OpenCV’s OpenGL window doesn’t do much else.
1 Like
berak
November 8, 2023, 7:30pm
3
what did you try ?
even with plain opengl it needs an awful lot of state changes to switch from 3d to 2d mode (and back)
i remember something like:
void RGL::enter2D()
{
static GLint view[4];
glGetIntegerv( GL_VIEWPORT, view );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D( view[0], view[2], view[1], view[3] );
glPushAttrib( GL_ALL_ATTRIB_BITS );
}
void RGL::leave2D()
{
glPopAttrib();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
1 Like
Ziri
November 16, 2023, 5:56am
4
thank you. I wasn’t able to display on the top of the texture because I didn’t leave 2D!
I ended up with something like this :
void on_image_update_clbk(void* param)
{
/*draw image */
cv::Mat* MatPtr = (cv::Mat*)param;
draw_image2d(MatPtr);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0.0f, image_with , image_height, 0.0f, 0.0f, 1.0f);
/*draw line*/
DrawLine line(cv::Point2f(0, 0), cv::Point2f(500, 500));
draw_line(line, 5);
std::string str = "this is some text ...";
draw_text(str, cv::Point2f(300, 500), 3, DrawColor(0.0, 0.0, 200));
}