C++ OpenCV 和创建 GUI
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6823534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV and creating GUIs
提问by Simplicity
Can I use OpenCV
to create GUIs that contain buttons, list boxes, ...etc for example?
例如,我可以OpenCV
用来创建包含按钮、列表框等的 GUI 吗?
Thanks.
谢谢。
回答by Simon
OpenCV has highguibuilt-in for making GUIs.
OpenCV内置了用于制作 GUI 的highgui。
You can find online tutorialsto get you started.
您可以找到在线教程来帮助您入门。
Note that this is not an extensive GUI library. You can only do basic stuff like opening windows, drawing points, anti-aliased lines, rectangles and text. There is a sliderwidget that can be used as a on-offbutton. If you need more than that, you can either
请注意,这不是一个广泛的 GUI 库。您只能执行基本操作,例如打开窗口、绘制点、消除锯齿的线条、矩形和文本。有一个滑块小部件可用作开关按钮。如果您需要更多,您可以
- build stuff yourself (for instance drawing a rectangle with text to make your own button), or
- use another library like Qtwhich provide plenty of widgets (buttons, menus, lists, dialogs…)
- 自己构建东西(例如用文本绘制一个矩形来制作自己的按钮),或者
- 使用另一个库,如Qt,它提供了大量的小部件(按钮、菜单、列表、对话框……)
Good luck if you go for the first one!
如果你去第一个,祝你好运!
回答by Simplicity
In the Learning OpenCV
, the following title is mentioned in page 101
: No Buttons.
在Learning OpenCV
,页面中提到了以下标题101
:No Buttons。
And, this is some what is mentioned under this title:
而且,这是标题下提到的一些内容:
Unfortunately, HighGUI does not provide any explicit support for buttons. It is thus common practice, among the particularly lazy,to instead use sliders with only two positions. Another option that occurs oft en in the OpenCV samples in …/opencv/ samples/c/ is to use keyboard shortcuts instead of buttons (see, e.g., the fl oodfi ll demo in the OpenCV source-code bundle).*
不幸的是,HighGUI 没有为按钮提供任何明确的支持。因此,在特别懒惰的人中,通常的做法是使用只有两个位置的滑块。在 .../opencv/samples/c/ 中的 OpenCV 示例中经常出现的另一个选项是使用键盘快捷键而不是按钮(例如,参见 OpenCV 源代码包中的 Floodfill 演示)。*
回答by jonsca
Along with the highgui
functions that Simon has pointed out, others have used OpenCV in conjunctionwith Qt. It is possible to translate the camera frames into images on a QLabel widget, and update the image on the label periodically.
随着highgui
西蒙指出的功能,而其他人使用OpenCV的结合与Qt的。可以将相机帧转换为 QLabel 小部件上的图像,并定期更新标签上的图像。
回答by Dmitry Pryadkin
On windows, you may use cvGetWindowHandle to obtain window handle (HWND). With that handle you may call CreateWindow from WinAPI and put WinAPI controls on that window.
在 Windows 上,您可以使用 cvGetWindowHandle 来获取窗口句柄 (HWND)。使用该句柄,您可以从 WinAPI 调用 CreateWindow 并将 WinAPI 控件放在该窗口上。
But you will also need to override or hook the WindowProc that was set by OpenCV for that window. Hooking and overriding explained here Multiple WndProc functions in Win32
但是您还需要覆盖或挂钩 OpenCV 为该窗口设置的 WindowProc。在此处解释挂钩和覆盖Win32 中的多个 WndProc 函数