OpenGL to OpenCV

asked 2015-09-18 05:29:21 -0600

MRDaniel gravatar image

updated 2015-09-18 05:29:48 -0600

Hello,

It is possible to set an OpenCV Mat as the background of an OpenGL window and to draw a 3D object on top of it.

How would you then add another layer?

For instance. Background subtraction gives you a background and foreground. Let's say you set the subtracted background as the OpenGL window background and then draw an object, say a sign on a wall. The we have the foreground that we wish to overlay on this new image.

We need to draw the foreground in OpenGL, which seems hard as these are not models but an overlay image.

We take the image from the OpenGL buffer, somehow, and then use normal Opencv image processing.

Any tips?

Regards,

Daniel

glEnable(GL_TEXTURE_2D);
  textureData = loadTextureData("textures/trashbin.png");
  cv::Mat image = cv::imread("textures/trashbin.png");
  if(image.empty()){
      std::cout << "image empty" << std::endl;
  }else{
      glGenTextures( 1, &textureTrash );
      glBindTexture( GL_TEXTURE_2D, textureTrash );
      glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
      glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_REPEAT );
      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
      glTexImage2D(GL_TEXTURE_2D,0,3,image.cols, image.rows,0,GL_RGB,GL_UNSIGNED_BYTE, image.data);
  }
edit retag flag offensive close merge delete

Comments

In opencv image are in Format BGR so I think GL_BGR or GL_BGRA. For GL_BGRA you have to check if your image image have 4 channels using image.channels(). I think you have to check if your data are continuous

LBerger gravatar imageLBerger ( 2015-09-18 08:53:25 -0600 )edit