Thursday, March 24, 2011

What are my GUI options?

Evaluating my GUI options for Windows PC applications
  1. Windows Forms (.Net) with C++ or C#; .Net port of Emgu Project
  2. MFC (Native) - Visual Studio Standard/Professional and up
Nokia -> Digia?
  1. Qt: Visual Studio - Qt-add-in to take care of the Qt-specific compilation process. Visual Studio Standard/Pro and up.
  2. Qt: QT Creator
Win32++: Does it have widget like OpenFileDialog?

1. HighGUI + Qt as back-end
2. There is a window_gtk.cpp, wonder if it works on Windows also.

Initial thoughts
Based on what I read from various internet discussions, I could use another GUI framework while keeping highGUI module for image, (camera) video, encode/ decode/read/write. The only work I need to write is to implement cvDrawImage().
Like C# but afraid that .Net would slow down execution. And wonder if C# port would introduce another set of issues/bugs.
The pros of choosing Qt is the cvDrawImage() is already there in window_QT.cpp.

Going with Qt

Problem with MSVC OpenCV DLL
Installed QTCreator. Created a simple app that open a file with the QT File Dialog. It uses OpenCV API to open an image file. Result: C API compiled and ran fine (cvLoadImageM()). Using the corresponding C++ API got linking error (undefined references to cv::imread()). Made the case simpler by trying cvGetTickCount(). Again the C API worked while C++ function cv::GetTickCount() did not. This is the configuration I used for building the application:
Tried to fix the problem with 'reimp' MinGW utility like this:
Unfortunately, 'reimp' did not like opencv_core220d.lib. Giving error 'invalid or corrupt import library'. Someone filed a bug report on this, not sure if that's the same case
Someone points to this article to describe the common issues of linking C++ libraries built with different compilers:
Giving up on this for now.

Debugger failed to step into OpenCV DLL
Even though calling OpenCV C API worked, I was unable to get the debugger to step into OpenCV functions. Installed 32-bit Debugging Tools for Windows (x86). Enable CDB in QTCreator Options menu. Followed instructions here: ; Still cannot get it to work.

OpenCV MinGW Build
Since QTCreator compiles with the MinGW toolchain. Rebuilt OpenCV 2.2 with latest stable version of MinGW(not the one packaged with QTCreator). Instructions here: ; Encountered a error linking with VideoInput.a - and the workaround is described here:
The OpenCV was then built successfully. There are some compilation errors with the C/C++ samples. g++ doesn't like:
vector<vector<Point>> cpoints So I changed to this vector<vector<Point> > cpoints
Fixes are trivial. I am now able to run both the adaptiveskindetector and camshiftdemo from the command-line. It can even read from the webcam right away!

MinGW versions
QtCreator uses its own MinGW. The gcc version is 4.4. The latest MinGW that I used to build OpenCV is gcc4.5.2. It caused problem at runtime. I fixed it by setting the PATH such that the newer MinGW DLLs are picked up.
Debugger: Unusably slow stepping in OpenCV DLLs. Wonder why.... Related to this?!
The qmake manual says automatic code completion and syntax highlighting will be available from external libraries after they are declared in the INCLUDEPATH and LIBS variables. I noticed that it only works if the directory is assigned to INCLUDEPATH as literal string, not a variable value $().

At the end...
I am able to get the application to open an image and display it correctly. It uses OpenCV C++ API to load image - swap color channels from BGR to RGB. The display part uses QtGraphicsScene and QtGraphicsView to show the QtImage.

Here is a hyperlink found in window_QT.hpp, a Qt article on how to interactively pan and zoom images smoothly


  1. Hi,
    you may be interested by this:

  2. Thanks for the pointer. It seems like your(?) QT Application development environment is Linux + Code::Blocks. And you mentioned about the dreaded 'moc' thing :-) I used Qt Creator and I think it runs the 'moc' behind the scene. But I am on Windows. Wonder if Qt Creator has Linux version.

  3. Yes Qt Creator is available under Linux; I don't use it though. I tried Qt Designer yesterday under Windows for the first time; it's nice that everything's going on behind the scene, but I'm not sure if I like the code generation.
    What keeps me busy right now is the qmake build command line and the include path for my Qt vision project on Visual Studio 2010, I can't find the way to had my Point Grey camera lib and includes files, even if it worked perfectly fine in adding OpenCV lib and includes... :-/ I'd love to get more time doing actual computer vision, instead of all this boring setup overhead...

  4. You are not alone, I also spend time converting data formats from various sources. Write scripts and apps to run, collect, and tabulate results. And don't get me started on Makefiles...

  5. Indeed Qt Creator is much easier to setup. I develop OpenCV using Qt and the debug is not that bad, but you have to compile in debug mode.

  6. You could still try Java :D

    QT Creator is way easier to set up than Visual Studio + QT addin, true. But still, at a lot of places they use Visual Studio, so you might think about getting used to it ^^.