Ever since QtCreator 1.0 came out, I have been a fan of this IDE. It replaces Eclispe CDT very nicely in term of speed, debugging support, nice syntax coloring and feature set. However, one of the biggest features which was missing in 1.0 was CMake support. This feature has been filled in QtCreator 1.1 (along with many other improvements) making QtCreator a premier choice for cross-platform C++ development.
Here is how you would use CMake with QtCreator 1.1. I use Ubuntu 9.04 but I believe any equivalent system would do
- Get the latest version of CMake GUI from the repo: sudo apt-get install cmake-gui
- Get the latest version of QtCreator (1.1) : download it from http://www.qtsoftware.com/products/developer-tools
- Install QtCreator by running the bin file that you have downloaded (make sure to chmod +x it so you can run the file)
- Start CMake GUI. Configure your project as you normally would. Make sure to choose "CodeBlocks - Unix Makefiles" generator. Also. the variable CMAKE_BUILD_TYPE has to be Debug if you want to debug your project. Otherwise, your debugger will not bind, your breakpoint is never reached and you feel as if QtCreator is not working with CMake when you try to debug.
- Start QtCreator. Choose Menu -> File -> Open ... . Open the CMakeLists.txt file for which you recently configured.
- Voila. You now have a working QtCreator project generated with CMake.
Happy QtCreatoring.
I believe that QtCreator is awesome because it is written by the same language it targets to serve by the people who understand this language and care about its development. In comparison, Visual Studio C++ is a half-baked product as Microsoft spends most of their time on Visual Studio C#. Visual Studio C++ (even the 2008 version) doesn't resolve function/method declaration or definition well. Intellisense is broken everywhere and the hotkeys leave one wonders if the developers are aliens whose hands are shaped differently from normal humans. XCode on OSX is a decent system although its main target is Objective-C. My limited usage of XCode has always led me to frustration as I keep asking how I can accomplish simple tasks. Eclipse CDT is slow and its support for CMake is spotty as best. On the other hand, These IDE perform extremely well when used for its main language. Visual Studio C# rocks, Eclipse support for Java is awesome especially on refactoring tools, XCode is no doubt the premier IDE on OSX for Obj-C. That's why for all those C++ developers out there, QtCreator is your best choice.
If you have not tried QtCreator, you should. I am sure it will give you a good experience.
For all those Vim users out there, QtCreator has Vim-mode that would satisfy your need while still allowing you to debug in a nice GUI.
For all those non-Qt developers out there, QtCreator works equally well for non-Qt projects. However, since Qt is LGPL, why not use at least QtCore given that it provides really good base classes (QString, QtConcurrent, Image IOs, ...)?
And, for all those who are new to C++. QtCreator is the best for you as well.
(0) Trackbacks • Permalink
OpenCV is a fine library. Its data structures are elegantly design to have both speed and compatibility. OpenCV includes HighGUI library which handles IO with files and displaying of images. It can also take input from the users from a trackbar. However, even OpenCV documentation says that you need to use a more complete GUI library if you need to do more than just prototyping. This is where Qt comes in.
Qt, as I might have stated before, is the missing library of C++. It has many features built-in making it a premier choice for any C++ developer. If you are going to use OpenCV with Qt, you will soon run into the problem of convert an image in OpenCV IplImage format to Qt QImage format. e.g. you grab a frame from your webcam and you want to display this in your Qt application.
Since this is a fairly fundamental task, it should be run as fast as possible. There are several solutions for this:
- Full blown solution that handles many different types of IplImage, (search on QtCentre.org for this well-established solution)
- Using memcpy to copy every 3 bytes of IplImage to QImage (solution by pherthyl)
- My method: convert IplImage to RGB then tell QImage to use this data in the memory
I have tested my method against method 2 and it is 18 ms (mine) vs 25 ms (method 2) on a 512x480 3-channel image (fruits.jpg from OpenCV example). Here is the code in C++ that does the comparison. You can also see my implementation of conversion from IplImage to QImage in here. A more detailed implementation of Qt and OpenCV integration for face detection can be found here.
(1) Trackbacks • Permalink
For a homework, I had to solve a rectangular sparse matrix (Ax=b). There are two ways to do this that I know of:
- Compute A.T (transpose of A). Then solve the square matrix A.T * A * x= A.T * b
- Run a least square optimization for on (A,b) directly.
So I set out to find the sparse matrix library / sparse matrix solver. I have tried several and here are my subjective reviews on each of them based on my approximately 5-10 hours of trying to get each of them to work (total about 40 hours).
OpenCV
Since my program is already written in OpenCV (C interface), my natural choice is to try to use cvSolve to solve my matrix. However, cvSolve can only solve a dense matrix. Thus, I need to convert my sparse matrix to a desnse one. OpenCV gives me allocation error since my matrix in dense format will take approximately 7GB of memory. I split the matrix into smaller square regions that can fit into OpenCV matrix structure. However, solving for these small regions with cvSolve is prohibitively time-consuming.
Intel Math Kernel Library
Intel is kind enough to offer free usage for Linux developer. Since my code is non-commercial and freely available when ask, I decide to give MKL a go. I have to note that Intel has extensive documentation on MKL. In fact, too extensive that the sheer amount of lines I have to wade through for each function distracts me. This led to errors in my code where I call the wrong function. Many of MKL functions are BLAS-like so the signatures are both long and cryptic to new comers.
MKL provides DSS and PARDISO for solving sparse matrix system. However, they only solve square matrices. This means I have to use method 1 (above). The irony is MKL does not (yet) provide a sparse matrix-sparse matrix multiplication. You can only multiply sparse matrix with dense matrix. I wasted a solid 20+ hours trying to get MKL to work but eventually gave up.
UPDATED March 12th, 2009: After asking for help on Intel Software Developer Network, I was pointed to a new addition to MKL 10.1: mkl_?csrmmultcsr. This method allows you to multiply two sparse matrices in compressed sparse row format. Thus, using this method, you can build transpose(A) * A and transpose(A) *b. Then you can feed these data into MKL Direct Sparse Solver to get your result.
Netlib Sparse
This is a very old library (written in 1988) in UC Berkeley. The library has rather extensive documentation. However, due to its age, the syntax is not standard C. This will cause many errors to pop up if you are using a standard-compliant compiler GCC. I have to add the prototypes for all the functions of this library in order to please GCC 4.2. After managing to get it to compile, I try to follow its documentation to solve a simple square matrix. All I get is segmentation fault. Due to its lack of samples and documentations, I eventually gave up after fruitless hacking.
CSparse
CSparse appears at first to be very promising library. It offers solving of rectangular sparse matrix and have well-named functions. However, its documentation offers little in term of how to allocate/deallocate memory for its matrix structure. The task of assigning values to the sparse matrix is also vaguely described. I spent a whole day on the ilbrary trying to get it to solve a simple rectangular matrix but ended up throwing in the towel. (UPDATED: see below)
So what happen next?
I eventually resolved to using Scipy + Mayavi. Not only is the functions in Scipy Sparse module easy to understand, the manipulation of matrix by Numpy is also top-notch. I set up my GVIM and iPython to work together similarly to Matlab command line and editor. However, the editing features of GVim is vastly superior to Matlab while iPython command line offers similar feature as Matlab command line. Overall, I am very happy with the use of Scipy and Mayavi. My visualization of the final result is also top-notch and the ability to switch between different colormap on the fly is a nice plus.
It is also worth noting that since OpenCV has an interface for Python, I am able to load an opencv matrix from my C code with two function calls (cvGetMat(cvLoadMat("filename.txt")). Converting this matrix to numpy matrix involves some simple nested for loops however. I include here the code to convert a CvMat saved to a file with cvSave function into a numpy array:
UPDATED on 3/7/2009: I later on found a newer incarnation of CSparse known as CXSparse. CXSparse is more compatible with newer compilers. It is included as part of libsuitesparse-dev package in Ubuntu. This makes installation of CXSparse a breeze. The documentation of CXSparse is very sparse. You are recommended to grab the book by Timothy Davis (author of CXSparse). While the book might seems confusing at first, you can just skip directly to the documentation of a specific function.
I reverted from Python and used CXSparse to solve my problem. I recommend it if you are trying to find a Sparse Matrix library.
(66) Trackbacks • Permalink
I am taking Computer Vision this semester. Needless to say, this is one of my favorite topic. So far, everything is progressing well. However, for the homework that I need to complete, I have to solve a system of linear equation with more equations than unknown. This system is huge (60000 by 30000) and is very sparse. I have tried (cursorly) GSL, and uBlas. However, they don't support sparse matrix representation. OpenCV (the main library for my homework) doesn't solve sparse matrix. I spent 2 days trying to get MKL to work but the exact function(s) that I need to call for MKL still alludes me. I am quite frustrated with this matter. I wonder if this is the reason that everyone is using Matlab (or Scipy). My friend prototyped the solution in 15 minutes in Matlab. It does take 5 minutes to run but he got the result right away. For me, I am still struggling to figure out how to solve my matrix.
(63) Trackbacks • Permalink
Life is better this New Year
Although I have not gone through the list of things that I would like to do this year yet, I have found several solutions to the annoyances that I encountered last year. First of all, I found Virtual Assist X. This is an add-on to Visual Studio that allows me to work much more productively (read: less mouse, more keyboard + refactor C++ code). No longer do I whine about opening files, refactoring code, creating functions, changing function signature and finding symbols. The new Intellisense of Virtual Assist X is so good that working without it feels much more painful now
.
I also threw away Metacity (hence Compiz) in favor of xmonad. I feel so much more at home with it. I guess my addiction with keyboard is growing everyday. Now only if I can play WoW without using my keyboard that would be awesome.
(65) Trackbacks • Permalink
Visual Studio annoyances
I believe that most developers work with more than 20 files in their project at a time. When I want to switch from one file to another, in Eclipse, I do Ctrl-Shift-R, type some letters and Eclipse will guess the file I want to open. I hit Enter and start typing away. In Visual Studio, there is no such thing, I can use the Quick Find hack by doing Ctrl-D, type ">of" then type the filename while hunting through a list of file that is stupidly suggested. Such a waste of time.
Then, there are times I have a function name under my cursor, I want to go to the definition of such function, Visual Studio always get it wrong. Every single time, it would show me the declaration of such method in my .h file. Why is it so hard to get a decent editor integrated in Visual Studio.
Then, there is this stupid keyboard shortcut combo Ctrl-K Ctrl-C which I have to hit in order to comment out a piece of code. Who in the world think that such combo is a better idea than Ctrl-/ is out of their mind. There is also no way to toggle commenting, you HAVE to know the uncomment combo as well. Pure stupidity.
Either I am doing something wrong or I am just plain stupid. Or both ![]()
(64) Trackbacks • Permalink