Showing posts with label opencv. Show all posts
Showing posts with label opencv. Show all posts

Opencv Compiling and installing for Gumstix

Opencv Compiling and installing for Gumstix
It's common sense that OpenCV is one of the best computer vision libraries available nowadays and it's certainly very useful to benefit from it in embedded environments. There's a trade-off between locally processing images and uploading them for remote processing, but some algorithms might as well run smoothly on embedded devices.

In order to compile OpenCV for Gumstix, firstly one needs to download it from:
http://sourceforge.net/project/showfiles.php?group_id=22870

The version I've testes was opencv-linux 1.1pre1, but I believe any other release will barely follow the same ideas provided here.
After the file has been extracted (tar -xzvf opencv-1.1pre1.tar.gz), one should configure the environment variables for the compiler:

export CC=/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc
export CXX=/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-g++

$ ./configure --host=arm-linux --build=i686-linux --prefix=/home/developer/opencvgum --without-gthread --without-gtk --without-python --disable-apps


Notice that we've defined that the prefix=/home/developer/opencvgum is the place it will be installed when we type 'make install'. By the way, make sure you have created this directory.
Be sure to substitute the /home/developer path to your user path, as well as the /gumstix/gumstix-oe/ to your installed gumstix environment.
We've also disabled the gtk environment since we are not interested in running the GUI applications inside the gumstix. I've also disabled python and building the applications.
Now that configuration has been successful. Type:

$ make

And then:

$ make install

If everything went well, you'll have the binaries and samples installed to /home/developer/opencvgum
Now, it would be useful to try and compile the samples so that we are sure they will run in the Gumstix.
In order to build them, go to /home/developer/opencvgum/share/opencv/samples/c and edit the build_all.sh script.
Make it executable:

$chmod +x ./build_all.sh


And then change all gcc and g++ to its arm-likes. My build_all.sh ended up like this:
#!/bin/sh
export PKG_CONFIG_PATH=/home/developer/opencvgum/lib/pkgconfig/

if [[ $# > 0 ]] ; then
base=`basename $1 .c`
echo "compiling $base"
/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
else
for i in *.c; do
echo "compiling $i"
/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
done
for i in *.cpp; do
echo "compiling $i"
/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
done
fi
Notice that we've also defined the export PKG_CONFIG_PATH=/home/developer/opencvgum/lib/pkgconfig/ so that the correct includes and linked libraries are built correctly.
Run this command and you'll notice the executable files will be created. I think that if you don't disable the flag "--disable-apps" in the configure application and make this change to the build_all.sh earlier it might also work.

Well, now that OpenCV has been built, you should be able to copy it to your gumstix. There's a small problem though. If you compact the files, you'll notice it's very big, so, a good idea is to delete a couple files we are sure we are not going to use.
An advice would be to delete some of the haarcascades.

Choose some of them you are sure you won't use, like the haarcascade_profileface.xml inside the data sub-directory, for instance. Delete a couple others as well.
This way, you'll be able to create a .tar.gz of around 6.5MB.
When it's done, copy it to your gumstix through scp:

$scp opencvgum.tar.gz root@192.168.YOUR-GUM.IP:/tmp

Make sure you copy it to /tmp, because you'll probably be out of space copying it somewhere else.
Extract it and then try to run one of the demos that does not use windows... the ./letter_recog application, for instance... it's located at:
/tmp/opencvgum/share/opencv/samples/c

Well, you might be able to see it running. Else, some libstdc++.so is missing error could also happen.
This means you don't have this library installed. One easy way to install it is through the command

$ipkg install libstdc++6

In case some other libraries are missing as well, repeat the procedure with their names. Notice that some packages have odd names.
For instance, if you had typed:
$ root@gumstix-custom-verdex:/usr/share$ ipkg install libstdc++

Then you'd have received the following message:

Nothing to be done
An error ocurred, return value: 4.
Collected errors:
Cannot find package libstdc++.
Check the spelling or perhaps run 'ipkg update'

Actually the name of the library is libstdc++6. Make sure you type the correct library name.

Well, in case libstdc++ is really installed, you might as well get some error like:

./letter_recog: error while loading shared libraries: libcxcore.so.2: cannot open shared object file: No such file or directory

It means the LD_LIBRARY_PATH is not pointing at your opencv libraries.
Simply type:

$ export LD_LIBRARY_PATH=/tmp/opencvgum/lib/

You will eventually be able to run your letter_recognition application.
Well, in case you want to run other applications, like the face recognition one, make sure you disable the GUI related functions and write your results to files.

Supportted Image formats for Opencv

Supportted Image formats for Opencv
–Windows bitmaps -BMP, DIB;
–JPEG files -JPEG, JPG, JPE;
–Portable Network Graphics -PNG;
–Portable image format -PBM, PGM, PPM;
–Sun rasters -SR, RAS
–TIFF files -TIFF, TIF.

Please add more in comments if any more formats support

How to Compile Opencv Program

How to Compile Opencv Program
Linux:
g++ hello-world.cpp -o hello-world \
-I /usr/local/include/opencv -L /usr/local/lib \
-lm -lcv -lhighgui -lcvaux

Windows:
In the project preferences set the path to the OpenCV header files and
the path to the OpenCV library files.

OpenCV naming conventions

OpenCV naming conventions
Function naming conventions:
cvActionTargetMod(...)
Action = the core functionality (e.g. set, create)
Target = the target image area (e.g. contour, polygon)
Mod = optional modifiers (e.g. argument type)
Matrix data types:
CV_(S|U|F)C
S = Signed integer
U = Unsigned integer
F = Float
E.g.: CV_8UC1 means an 8-bit unsigned single-channel matrix,
CV_32FC2 means a 32-bit float matrix with two channels.
Image data types:
IPL_DEPTH_(S|U|F)
E.g.: IPL_DEPTH_8U means an 8-bit unsigned image.
IPL_DEPTH_32F means a 32-bit float image.

Header files:
#include
#include
#include
#include // unnecessary - included in cv.h

Opencv Modules

Opencv Modules
cv - Main OpenCV functions.
cvaux - Auxiliary (experimental) OpenCV functions.
cxcore - Data structures and linear algebra support.
highgui - GUI functions.

Features Of Opencv

Features Of Opencv
* Image data manipulation (allocation, release, copying, setting, conversion).
* Image and video I/O (file and camera based input, image/video file output).
* Matrix and vector manipulation and linear algebra routines (products, solvers, eigenvalues, SVD).
* Various dynamic data structures (lists, queues, sets, trees, graphs).
* Basic image processing (filtering, edge detection, corner detection, sampling and interpolation, color conversion, morphological operations, histograms, image pyramids).
* Structural analysis (connected components, contour processing, distance transform, various moments, template matching, Hough transform, polygonal approximation, line fitting, ellipse fitting, Delaunay triangulation).
* Camera calibration (finding and tracking calibration patterns, calibration, fundamental matrix estimation, homography estimation, stereo correspondence).
* Motion analysis (optical flow, motion segmentation, tracking).
* Object recognition (eigen-methods, HMM).
* Basic GUI (display image/video, keyboard and mouse handling, scroll-bars).
* Image labeling (line, conic, polygon, text drawing)

What is OpenCV

OpenCv
1) Open source computer vision library in C/C++.
2)Optimized and intended for real-time applications.
3)OS/hardware/window-manager independent.
4)Generic image/video loading, saving, and acquisition.
5)Both low and high level API.
6)Provides interface to Intel's Integrated Performance Primitives (IPP) with processor specific optimization (Intel processors).

Or


OpenCVOpenCV means Intel®Open Source Computer Vision Library. It is a collection of C functions and a few C++ classes that implement some popular Image Processing and Computer Vision algorithms.