Thursday, March 24, 2011

What are my GUI options?

Evaluating my GUI options for Windows PC applications
Microsoft
  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?

OpenCV
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: http://www.barbato.us/2011/03/18/using-opencv2-within-qtcreator-in-windows-2/
Tried to fix the problem with 'reimp' MinGW utility like this: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
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 http://sourceforge.net/tracker/?func=detail&atid=102435&aid=3120866&group_id=2435
Someone points to this article to describe the common issues of linking C++ libraries built with different compilers: http://chadaustin.me/cppinterface.html
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: http://msdn.microsoft.com/en-us/windows/hardware/gg463016.aspx ; 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: http://opencv.willowgarage.com/wiki/MinGW ; Encountered a error linking with VideoInput.a - and the workaround is described here: https://code.ros.org/trac/opencv/ticket/587
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!

QtCreator
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?! http://bugreports.qt.nokia.com/browse/QTCREATORBUG-3115
qmake
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.

Resources
http://thomasstockx.blogspot.com/2011/03/qt-472-in-visual-studio-2010.html
Here is a hyperlink found in window_QT.hpp, a Qt article on how to interactively pan and zoom images smoothly
http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming

6 comments:

  1. Hi,
    you may be interested by this:
    http://citizenstefjournal.blogspot.com/2010/12/qt-opencv-project.html

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

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

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

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


    vimeo.com/edis

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

    ReplyDelete