如何将 OpenCV 与 OpenGL 集成 (Visual C++ 2008)
我编写了两个代码,使用 OpenCv(用于标记检测)和 OpenGL(用于创建简单的 3D 框)。但我不知道如何整合这两者。例如:在 OpenCV 窗口上显示框。
当我尝试调用OpenCV和OpenGL的以下两个函数时,似乎只有OpenGL函数在执行。 (仅创建了 OpenGL 窗口,但现在创建了 OpenCV 窗口)
int main(int argc, char** argv){
initGL(argc, argv); // basic initialization steps for OpenGL
glutMainLoop(); // shows 3D scene in a new window
startOCV(); // shows camera stream in a new window
return 0;
}
谢谢
I have written two codes, using OpenCv (for marker detection) and OpenGL (for creating a simple 3D box). But I'm having no clue on how to integrate those two. ex: Displaying the box on a OpenCV window.
When i tried to call the following two functions of OpenCV and OpenGL, only OpenGL functions seem to be executing. (OpenGL window is only created, but now OpenCV one)
int main(int argc, char** argv){
initGL(argc, argv); // basic initialization steps for OpenGL
glutMainLoop(); // shows 3D scene in a new window
startOCV(); // shows camera stream in a new window
return 0;
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码将在
glutMainLoop
上阻塞,因此您需要在其之前调用startOCV
。如果
startOCV
也阻塞,您需要运行此函数一个线程,以便main()
可以继续执行glutMainLoop
。编辑::
但正确的做法是相反< /a>:将 OpenCV 的图像复制到 OpenGL 纹理并将其渲染到OpenGL 窗口。
Your code will block on
glutMainLoop
, so you need to callstartOCV
before it.And if
startOCV
blocks as well, you need to run this function in a thread so thatmain()
can go on and executeglutMainLoop
.EDIT::
But the right way to do is the other way around: copy OpenCV's image to an OpenGL texture and render that to the OpenGL window.
您可以尝试最新的 OpenCV trunk。他们将OpenGL集成到highgui(OCV显示模块)中。它可能会让您的生活更轻松,并为您解决问题。
不要忘记任何主干版本都可能有缺陷并且没有文档记录。下一个正式版本尚未计划。
You can try the latest OpenCV trunk. They integrate OpenGL in highgui (OCV display module). It may make your life easier, and solve the problem for you.
Don't forget that any trunk version can be buggy and a bit undocumented. The next official release is not yet planned.
我有类似的问题,这就是我解决它的方法。我有用于捕获使用 OpenCV 的相机流的代码,并在无限 while 循环中运行,以及使用 openGL 和 glut-
glutMainLoop()
的动画。我将用于捕获相机流的 openCV 代码放在更新函数中 - 并在 main.c 中调用 glutTimerFunc(TIMER_MS, update, 0) 。动画和相机流现在都可以工作。然而,它确实稍微减慢了动画速度。
I had similar problem and this is how I solved it. I had code for capturing camera stream which used OpenCV and run in infinite while loop and animation that used openGL and glut-
glutMainLoop()
.I put openCV code for capturing camera stream inside update function -and called
glutTimerFunc(TIMER_MS, update, 0)
in main. Both animation and camera stream are working now. However, it did slow down animation a bit.