-
-
Save qianqian121/c327957b5acf8134c56b81804cbead29 to your computer and use it in GitHub Desktop.
How to read an image by opencv, then copy it to a texture, and read it out at last.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::Mat img = cv::imread("img.png"); | |
GLuint tex_in; | |
glGenTextures(1, &tex_in); | |
glBindTexture(GL_TEXTURE_2D, tex_in); | |
/*By practice, the internalParam: | |
* GL_RGB, GL_RGBA, GL_RGB8, GL_RGBA8 work | |
* GL_RGB8UI, GL_RGBA8UI don't work | |
*/ | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, img.cols, img.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, img.data); // copy data to texture object | |
cv::Mat test(img.rows, img.cols, CV_8UC3); | |
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGR, GL_UNSIGNED_BYTE, (void*)test.data); // read the image out of texture object | |
cv::imshow("test", test); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment