我一直在寻找一种将OpenGL纹理转换为OpenCV矩阵类型的方法。我发现了许多指南,这些指南显示了从OpenCV矩阵到OpenGL纹理的转换,但不幸的是却没有相反的方法。我也阅读了此内容及其答案,但并没有使我变得更明智。我正在用C ++编写并使用OpenCV3.1和OpenGL4.4。
编辑:更新的代码
main.cpp:
#include "CameraCapture.h"
#include "GUIMainWindow.h"
#include "glfw3.h"
#include "Texture.h"
using namespace std;
int main(int argc, char* argv[]) {
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW \n");
return -1;
}
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(1929, 1341, "OpenGL", NULL, NULL);
if (window == NULL) {
fprintf(stderr, "Failed to make GLFW window.");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
CameraCapture *cc = new CameraCapture();
cc->CameraCapture::AvailableCameras();
GLuint texture = cc->CameraCapture::OpenCamera(0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
drawGLTexture(window);
Mat out = …Run Code Online (Sandbox Code Playgroud)