Thursday, May 24, 2012

Getting OpenCV libraries loaded in Matlab for Linux Ubuntu with LD_LIBRARY_PATH issues

It turns out there is a bug on Ubuntu that for some reason doesn't let you change LD_LIBRARY_PATH the way it used to. This is very annoying and you can read more about this on this link
So there are a few things you can do about this. What seemed to me simple to do and worked was to follow what this thread suggested which is basically use LD_PRELOAD before calling matlab in this way:

LD_PRELOAD=/home/OpenCV-2.0.0/lib/libcv.so:/home/OpenCV-2.0.0/lib/libcxcore.so matlab

One thing that I had to do was to be a super user (sudo su) before doing all this because I also needed root access from matlab and also it didn't seem to load these libraries if you just do "sudo matlab"
This is not a long term solution but at lest can get you going. I hope this helps.

Thursday, April 19, 2012

Installing Boost in Windows 7

I got this steps from
http://www.beroux.com/english/articles/boost_unit_testing/?part=2
However, the link to the download page was wrong. Here are more updated steps:

1. Download the latest Boost installer from BoostPro Computing: http://www.boostpro.com/download/
2. Install the setup:
Select whatever mirror you like and VS version you are working with.

[X] Mulithread Debug, DLL --DLL Debug, required when BOOST_DYN_LINK defined.
[X] Mulithread, DLL --DLL Release, required when BOOST_DYN_LINK defined.
[X] Mulithread --LIB (for CRT DLL) Release, default in Release.
[X] Mulithread Debug --LIB (for CRT DLL) Debug, default in Debug.
[X] Mulithread, static runtime --LIB (for CRT LIB) Release.
[ ] Mulithread Debug, static runtime --LIB (for CRT LIB) Debug.
[ ] Single thread, static runtime
[ ] Single thread Debug, static runtime

3. Add Boost to the include and library folders of Visual Studio:
Go to the menu Tools > Options...
Go to Project and Solutions > VC++ Directories
Add to your Include files: C:\Program Files\boost\boost_X_XX_X
Add to your Include files: C:\Program Files\boost\boost_X_XX_X\boost\tr1
Add to your Library files: C:\Program Files\boost\boost_X_XX_X\lib

Optional:
Path inclusion: If you use Boost DLLs (rare) you may add C:\Program Files\boost\boost_X_XX_X\lib to your system PATH.

Wednesday, April 4, 2012

How to use Bilateral Filter in Opencv

Here is an example of using the bilateral filter where 21 is the color sigma and and 3 is the spatial sigma

cvSmooth(gray_image_,smoothed_image,CV_BILATERAL, 0,0, 21, 3);

Thursday, February 23, 2012

Why Latex crashes when using \usepackage in windows

Today I had this problem again and seemed to be because latex usually downloads automatically the packages that it doesn't have. However, in windows when Latex doesn't have the rights, it won't download this files because windows might block this process thinking is a a virus.
One way to fix this is by running Latex as administrator. This is done by right clicking on the application and choose "run as administrator"
I hope this helps

Tuesday, February 7, 2012

Compiling a simple OpenCv program in Ubuntu

Here is a couple links that could help you in case you run into problems:
opencv.org and willowgarage.com

Update: Here I found a script that takes care of the whole installation in Ubuntu. You might want to try that first.
https://help.ubuntu.com/community/OpenCV

Otherwise:
First you need to install the required packages in your system.
You can use this script to do that. Feel free to edit it in case doesn't work for you.
Remember to use chmod 755 to change the execution rights of the file


1. Create a folder for opencv
mkdir opencv
cd opencv

2. Download the code from
git clone git://code.opencv.org/opencv.git
or
git clone https://github.com/Itseez/opencv.git

3. Create a release folder to store built files
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

(Remember that if you have a GPU installed you want to add the following parameters: -D WITH_CUDA=YES -D CUDA_TOOLKIT_ROOT_DIR="/usr/local/cuda/bin")
-Optionally you can add other options to the cmake line such as -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON

4. Run make inside release
make
sudo make install



5. Create a simple project using your favorite IDE. Here I just used vi:
vim image-display.c

6. Create a simple program such as:

#include "highgui.h"

int main( int argc, char** argv ) {
// cvLoadImage determines an image type and creates datastructure with appropriate size
IplImage* img = cvLoadImage( argv[1],1);

// create a window. Window name is determined by a supplied argument
cvNamedWindow( argv[1], CV_WINDOW_AUTOSIZE );
// Display an image inside and window. Window name is determined by a supplied argument
cvShowImage( argv[1], img );
// wait indefinitely for keystroke
cvWaitKey(0);

// release pointer to an object
cvReleaseImage( &img );
// Destroy a window
cvDestroyWindow( argv[1] );
}


7. gcc -ggdb `pkg-config --cflags opencv` image-display.c -o image-display `pkg-config --libs opencv`

8. run the program ./image-display "cat.jpg"



Wednesday, January 18, 2012

How to create a new OpenCV project with Visual Studio 2008

1. Download OpenCV 2.1 for VS2008

2. Create a new console project in VS2008

3. On properties project-> Configuration properties do the following :

C/C++ -> General-> Additional Include Directories enter:
C:\OpenCV2.1\include\opencv

4. Under Linker->General->Additional Library Directories enter:
C:\OpenCV2.1\lib

5. Under Linker->Input->Additional Dependencies (libraries) enter:
cv210d.lib
cxcore210d.lib
highgui210d.lib

6. You can test it using some code like:
#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
IplImage *img = cvLoadImage("image.jpg");
cvNamedWindow("Image:",1);
cvShowImage("image:",img);

cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);

return 0;
}

By: Matthew Stofflet