OpenCV and creating GUIs - c++

Can I use OpenCV to create GUIs that contain buttons, list boxes, ...etc for example?
Thanks.

OpenCV has highgui built-in for making GUIs.
You can find online tutorials to 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 slider widget that can be used as a on-off button. If you need more than that, you can either
build stuff yourself (for instance drawing a rectangle with text to make your own button), or
use another library like Qt which provide plenty of widgets (buttons, menus, lists, dialogs…)
Good luck if you go for the first one!

In the Learning OpenCV, the following title is mentioned in page 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).*

Along with the highgui functions that Simon has pointed out, others have used OpenCV in conjunction with Qt. It is possible to translate the camera frames into images on a QLabel widget, and update the image on the label periodically.

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.
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

Related

How to implement a VS-like window manager (floating tabs) with Qt?

I'm developing on a project that needs an interface with support of floating tabs similar to the ones in Visual Studio (as is shown below).
The interface is expected to provide the following features:
Several sub-windows are in the main window and can be added, removed or moved to another place;
When several sub-windows occupy the same space, they appear as several tabs;
Users can drag & drop the sub-windows (tabs) to move them to another place;
As the sub-windows are dragged beside one of the sides of the main window, they can be automatically docked to the side;
When a sub-window (tab) is not docked to any of the sides, it appears as a standalone window and can be located out of the range of the main window (to support multiple monitors).
So how can I implement such a VS-like window manager (if it is called so)? I am familiar with C++ and Qt and plan to implement such features with Qt.
I've tried two of the choices Qt provides to me, but both in vain:
I tried building a MDI application with Qt. I tried the official MDI example and found some problems:
The sub-windows are not automatically docked;
The sub-windows are not turning to tabs when they occupy the same space;
The sub-windows cannot be located out of the range of the main window.
I also tried using the dock widgets (mainly QDockWidget). I tried the official dock widgets example and also found some problems:
The central widget is useless, but once it is removed (programmatically, with answer in this question) the auto-docking feature seems broken;
The sub-windows can only be docked to one of the sides. For example, I cannot create 4x4 sub-windows in a main window.
So how can I implement such features with Qt and C++? Is there a handy solution provided by Qt, or do I have to implement these manually (by listening to the mouse events and set the correpsonding sub-windows)?
Thanks in advance!
I think I have had the answer.
The answer is: there's no easy way to do this with pure Qt. And QDockWidget is nearest to the perfect solution. If you would like to implement such features, you have to do so by yourself.
However, fortunately, there are implementations of such features by others, which can be found by searching through the Web. For example, by searching through GitHub, I have found 2 repositories that contain implementations of such features:
mfreiholz/Qt-Advanced-Docking-System
JackyDing/QtFlex5 (works on windows platform with DWM on only, according to its README)

Adding Menu bar to QT cvNameWIndow

I am trying to create video-player application with open CV using QT creator. using openCV it is possible to play video files by adding each video frame as an image on an instance of cvNamedWindow.
Now I would like to add a menu bar to this cvNamedWindow so that I can add File, help etc menus. menus. I looked up the documentation of cvNamedWindow and I couldn't find any clue. Any suggestions?
P.s. In opencv windows created using QMainWindow, it is straightforwaed to add menu bar. But what I want is to add the menu bar to cvNamedWindow not to a window created using QMainWindow.
OpenCV's user interface is quite limited, so there's no way to accomplish what you are looking for with OpenCV's API.
On the other hand, Qt has a rich API for building graphic applications. Luckily for you, I just shared cvVideo: an example that demonstrates how to play videos on a QWidget surface. Plus, the demo has some neat tricks to change aspect ratio modes. Almost forgot, it displays a simple QMenuBar too.
you can use createButton and createTrackbar with namedWindow, but that's it.
sure, you could simulate a menu with a row of buttons, but if you need something more advanced,
stick to the native Qt api.

How to create custom skin like WinAmp

I guess this question has been ask before, but I have not found sufficient answer to even start poking around. Most answer refers to catching WM_PAINT method directly and do custom rendering, or use a onwer draw object. However, I did not see a centralized place that has the info. to start researching. Hence, the question.
My goal is to create a very simple GUI program with custom look into it. I prefer the way winamp does their custom look that is customizable through "skins". However, I am not interested in using some cross-platform library like GTK+, QT or wxWidget.
I have some experience in system programming, but not much for GUI. I spent most of my time developing console applications, and I just started doing some QT development. If you can point me in the right direction, I'd be very appreciated.
PS: I am interested in both windows and linux environment.
Everybody,
Sorry for the late reply. I had a chance to have a quick talk with the original developer for winamp, and this is the quick answers I have:
Using skins: Artists create skins, developer will render the skins
To the OS (Windows), winamp is just one pretty box, nothing else. There is a container windows, and that's about it
All controls (button, label, list, etc) are implemented by winamp team themselves. All messages and stuffs are passed as relative position to the container window. WinAmp and the GUI engine has to decide if a button is clicked or if the label next to it is the target, etc.
Rendering artists skins created in XML
I do not have the details on if they use any libraries to do all that, but I am suspecting they do hook a window call directly, and do custom rendering themselves.
GUI skin usually using plug-in mechanism
I guess this is exactly what you are looking for:
https://www.linux.com/learn/tutorials/428800:weekend-project-creating-qt-interfaces-with-gimp?utm_medium=twitter&utm_source=twitterfeed
I also interested in creating custom look of window and widgets.
Speaking about widgets it's not hard, just need to create subclass (if you are using C++) or some widget and implement some methods like draw, handle etc. But this solution is good only if you use some high-level library like GTK, QT, etc. If you want to implement all controls by your own, you may get any graphics library, which can create window and do any graphics inside. For example, SDL2 + Cairo. SDL2 for creating window, Cairo for vector rendering controls/widgets. Both of this libraries are for win and linux. Another option is take opengl/vulkan + some lib for rendering window. It could be SDL2, SFML, GLFW.
If you really interested how it works on low level, then search Windows API for Windows and XLib or XCB for Linux/X.Org.
Speaking about window, I still investigate it. However I have one thought: you may create an empty window and then draw whatever you want. Then you need to add handlers for resizing window on the borders. But I am not sure if it's good solution, and if it won't freezes.

How to create a GUI without a frame in X11?

I'm trying to figure out how to create a graphical interface, in X11, which exists outside of a window manager's/desktop environment's standard window frame. For example, when Thunderbird finds new mail, it shows a special alert in the lower right hand corner of the screen which is shown without any frame (no close/minimize buttons, etc.).
I'm specifically interested in doing this in QT with C++, but if someone knows a solution with a different graphical library, that would be helpful too.
For QT pass Qt::FramelessWindowHint as a window flag when you construct your top level widget.
See here for more info:
http://doc.qt.nokia.com/main-snapshot/qt.html#WindowType-enum
You can do this with X as well although I haven't done so in a long time.
http://www.xfree86.org/current/XCreateWindow.3.html
With GTK you would use gtk_window_set_decorated(), which would probably be Gtk::Widget->set_decorated() (I think, I don't use gtkmm).
http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Window.html#a67adb1d8051a38e0e5272f141bb8778c

Is is possible to make a shaped, alpha-blended dialog?

I'm making a non-rectangular dialog, modelled over an image from Photoshop (the image is the background of the dialog, and the user will see trough the transparent part of the image). I'ts like a dashboard-style window for a media-app with a few custom-drawn controls. Most of the background-image is either opaque or 100% transparent - but in between there is a thin area of partially transparent pixels, ment to blend the image smootly into the background. This works great for web-graphics, but I have not found a way to make this work for Windows windows. I'm using the Windows Template Library (WTL), msvc 2008 - and the app must run on Windows XP as well as Vista and Windows 7.
Currently, I'm simply using the opaque part of the background-image to create a GDI clipping-region, but this gives pretty rough edges.
Does anyone know about any API functions to accomplish this (part of WTL, or reachable from WTL)?
Perhaps you could use layered windows? I haven't tested these with WTL but you should be able to get the effect you want. To the best of my knowledge I don't think you can add controls to a layered window so you'll need to attach it to another (non-layered) window to use controls.
Not sure how this interoperates with WTL, but have a look at the AlphaBlend function. You'll need to select your partially transparent bitmap into a DC and copy that to your dialog's DC in your paint function.
This article shows how to use layered windows with WTL and the Gdi+ API which is available on all your target platforms.