私はLinuxを使用しており、OpenGLをサポートするOpenCV 2.4.4をコンパイルしましたが、opengl_interop.hpp関数の使用方法についてはまったくわかりません(少なくとも私のバージョンのドキュメントでは、ドキュメント化されていないものもあります)。OpenGL が有効になっているセクションの window.cpp を見ると、関数 setOpenGLContext、setOpenGLDrawCallback、および updateView の使用に関するいくつかのヒントが見つかりましたが、この非常に単純なコードでさえ動作しません。
#include <opencv2/opencv.hpp>
#include <GL/gl.h>
#include <GL/glut.h>
#include <opencv2/core/opengl_interop.hpp>
using namespace cv;
void on_opengl(void* userdata);
int main(void)
{
VideoCapture webcam(CV_CAP_ANY);
Mat frame;
namedWindow("window", CV_WINDOW_OPENGL);
setOpenGlContext("window");
while(waitKey(30) < 0)
{
webcam >> frame;
setOpenGlDrawCallback("window", on_opengl);
imshow("window", frame);
updateWindow("window");
}
return 0;
}
void on_opengl(void* userdata)
{
glLoadIdentity();
glTranslated(0.0, 0.0, 1.0);
glRotatef( 55, 1, 0, 0 );
glRotatef( 45, 0, 1, 0 );
glRotatef( 0, 0, 0, 1 );
static const int coords[6][4][3] = {
{ { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
{ { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } },
{ { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
{ { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
{ { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
};
for (int i = 0; i < 6; ++i) {
glColor3ub( i*20, 100+i*10, i*42 );
glBegin(GL_QUADS);
for (int j = 0; j < 4; ++j) {
glVertex3d(0.2*coords[i][j][0], 0.2 * coords[i][j][1], 0.2*coords[i][j][2]);
}
glEnd();
}
}
ウェブカメラ ストリームで opengl を使用する正しい方法は何ですか? さよなら!