将 OpenCV 与大型程序集成
任何人都可以推荐操作指南或提供有关将 OpenCV 与更大的基于 GUI 的程序集成所涉及的内容的简要概述吗?流行的方法有哪些?
特别是,在不使用 HighGUI 的情况下进行视频捕获/预览时使用 OpenCV 处理视频似乎特别神秘。我希望有人能揭开这个谜团。
我的具体配置是使用 Juce 或 Qt,具体取决于可以做什么。跨平台的事情并不重要——如果在 Windows 中有一种很棒的方法可以做到这一点,我可能会相信。社区支持的可用性很重要。
我听说HighGUI完全是为了测试,不适合实际应用。有人推荐了 VideoInput 库,但它是实验性的。
答案要点:
- 使用Qt(因为Qt很棒并且有一个很大的社区)。
- 打开一个新线程以循环运行 cv::VideoCapture 并在帧捕获后
发出
信号。使用 Qt 的msleep
机制,而不是 OpenCV。 所以,我们仍然使用 OpenCV highgui 进行捕获。 将 cv::Mat 转换为 QtImage:
QImage qtFrame(cvFrame.data, cvFrame.size().width, cvFrame.size().height, cvFrame.step, QImage::Format_RGB888);
qtFrame = qtFrame.rgbSwapped();
可选:使用 GLWidget 渲染。使用Qt内置方法将QtImage转换为GLFormat:
m_GLFrame = QGLWidget::convertToGLFormat(frame);
this->updateGL();
Can anyone recommend a how-to guide or provide a brief overview of what's involved with integrating OpenCV with larger GUI-based programs? What are the popular ways to do it?
Particularly, processing video with OpenCV while doing video capture/preview without using HighGUI seems especially arcane. I hope someone can demystify this.
My particular configuration is with either Juce or Qt depending on what can be done. The cross platform thing is not critical -- if there is an awesome way of doing this in Windows, I might be convinced. The availability of community support is important.
I have heard that HighGUI is entirely for testing and unsuitable for real applications. Someone recommended the VideoInput library, but it is experimental.
Key points from answers:
- Use Qt (because Qt is great and has a big community).
- Open a new thread to run cv::VideoCapture in a loop and
emit
signal after frame capture. Use Qt'smsleep
mechanism, not OpenCV. So, we are still using OpenCV highgui for capture. Convert cv::Mat to QtImage:
QImage qtFrame(cvFrame.data, cvFrame.size().width, cvFrame.size().height, cvFrame.step, QImage::Format_RGB888);
qtFrame = qtFrame.rgbSwapped();
Optional: Render with GLWidget. Convert QtImage to GLFormat with Qt built-in method:
m_GLFrame = QGLWidget::convertToGLFormat(frame);
this->updateGL();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是我使用 Qt 的方法。欢迎您使用任何对您有用的东西:)
这个类处理将图像渲染到升级的 QWidget 上。接下来,我创建了一个线程来提供小部件。 (我在这里使用了 Qt 信号槽架构,因为它很简单......可能不是书中最好的执行器,但它应该可以帮助您入门)。
我花了一些时间才弄清楚这一点,所以希望它能帮助您和其他人节省一些时间:D
Here is how I am doing it with Qt. You are welcome to use whatever may be useful to you :)
This class handles the rendering of the image onto a promoted QWidget. Next, I created a thread to feed the widget. (I cheated using the Qt signal-slot architecture here because it was easy...may not be the best performer in the book, but it should get you started).
Took me a bit to figure that out, so hopefully it will help you and others save some time :D
创建一个 openCV 图像来保存您捕获的图像。
对它进行处理,然后将数据复制到要显示的图像中(例如 QImage)
您可以通过创建 opencv cv::Mat 图像来与 QImage 共享内存来优化
,但由于 QImage 通常使用 ARGB 和大多数图像处理任务最好以灰度或 RGB 形式完成,最好复制图像并使用 opencv cvtColor() 函数在它们之间进行转换
然后简单地包含 opencv 标头,并链接到 opencv 库 - 有opencv wiki 上针对您的特定环境的指南
Create an openCV image to hold the image you have captured.
Do processing on it and then copy the data into the image you want to display (eg QImage)
You can optomise things by creating the opencv cv::Mat image to share the memory with the
QImage but since QImage generally uses ARGB and most image processing tasks are better done as greyscale or RGB it's probably better to copy images and convert between them using the opencv cvtColor() function
Then simply include include the opencv headers, and link with the opencv libs - there are guides on the opencv wiki for your particular environment