Thursday, June 6, 2013

OpenCV in C/Eclipse - Quick install guide

We are going to setup now OpenCV in Eclipse. For that, we will follow the tutorial in: 
http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html#cascade-classifier

We start by creating a project. Follow these instructions.
http://docs.opencv.org/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html

Nevertheless, we got stuck in several places, so, here are the tips. First place was because I was selecting the wrong project, to start with.


I was going with GNU Autotools which, it seems, needs to be setup, etc... The right choice is "Executable" and the I picked the MinGW GCC. Found the solution here.

Also got stuck because I didn't know how to properly add the libraries in Eclipse. For details, read this and this. But even with that, I was doing some mistakes, so, here is the basics: 
  1. Add the path to the include (header files) directory. In our case it was (C:/eclipse/opencv/build/include). The individual paths are listed in the code, respect to this root... FYI, I did this in the C++ compiler options. Not in the C compiler.
  2. Add the path to the lib (compiled libraries) AND the libraries themselves. When adding their name, do not add the extension.
  3. Remember to use fwd slash "/" on the paths although I think it is ok because Eclipse will put it between "".
  4. Also, watch how the C libraries are defined. I didn't really have to add the path for them, but some examples didn't work when used without the .h. For instance, use #include <stdio.h> and not #include <stdio>.
Here is a screen shot of the whole thing, in case it helps with this or something else:


Notice that if you download the Opencv code of the link above is slightly different than the listed... They have few more includes, like:
#include "opencv2/core/utility.hpp"
#include "opencv2/highgui/highgui_c.h"

But I didn't need those to build.

Not sure why I need to use the x86 >> This may be because we may have selected this version of eclipse because of Qt?? Compiling with the libraries on x64 will not generate an exe but we don't get more errors than the one we get with x86 (make: *** No rule to make target `all'.). This error is weird because everything else works. And anyhow, I shouldn't need to create a rule because we have it in auto. On that sense, looking into the directories, notice that I don't have a makefile. I think that is normal. The tool has that internal but does not share it with us.

Another thing was that the program didn't start because libpencv_highgui245.dll is missing from your computer. That was just the first one that he looked for. All of them were missing.It basically has to do with dynamic linking. The dll is not included in the code (like it would with static), so, at run time needs to look for it and can't find it. See http://qt-project.org/forums/viewthread/12525. I solved by moving the 4 dlls to the debug directory.

GEEEE! Almost there! Just a last one... Remember to get the xmls. I put them in resources, following a procedure like the one described in the java tutorial. I had to add resources/ in front of the text. Works now from run. If you want to execute the exe, you then have to move it to the root of the project with all its dlls...

DONE!

PS.: Click here to see the index of these series of posts on OpenCV

No comments:

Post a Comment