Loading texture for OpenGL with OpenCV

后端 未结 4 1783
南方客
南方客 2020-12-25 10:15

I have seen many code samples for loading textures for OpenGL, many of them a bit complicated to understand or requiring new functions with a lot of code. <

相关标签:
4条回答
  • 2020-12-25 10:42

    from this doc, I suggest you to change your test:

    texture_cv = imread("stones.jpg");
    if (texture_cv.data != NULL)  {
      ...
    
    0 讨论(0)
  • 2020-12-25 10:50

    Another short question... I think you may need to use

    glTexImage2D(GL_TEXTURE_2D, 0, 3, texture_cv.cols, texture_cv.rows, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_cv.ptr());
    

    instead of

    glTexImage2D(GL_TEXTURE_2D, 0, 3, texture_cv.cols, texture_cv.rows, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_cv.data);
    
    0 讨论(0)
  • 2020-12-25 10:56

    Your error appears there, right?

    if( texture_cv = imread("stones.jpg"))  {
    

    because in if(expr) expr must be bool or can be casted to bool. But there is no way to convert cv::Mat into boolean implicitly. But you can check the result of imread like that:

    texture_cv = imread("stones.jpg");
    if (texture_cv.empty()) {
      // handle was an error
    } else {
      // do right job
    } 
    

    See: cv::Mat::empty(), cv::imread

    Hope that helped you.

    0 讨论(0)
  • 2020-12-25 10:56

    The assignment operator

    texture_cv = imread("stones.jpg")
    

    returns a cv::Mat that can't be used in a conditional expression. You should write something like

    if((texture_cv = imread("stones.jpg")) != /* insert condition here */ )  {
          //...
    }
    

    or

    texture = imread("stone.jpg");
    if(!texture.empty())  {
              //...
    }
    
    0 讨论(0)
提交回复
热议问题