Monday, April 24, 2006

Things that just don't work

An ongoing list:

cvMinMaxLoc on non-32F images
cvPyrUp / cvPyrDown on 32F images (works on 8U)

Why? Who knows.

Thursday, April 20, 2006

Getting Started with OpenCV in Visual Studio 2005


Step 1: Create a new project.


Step 2: Select Win32 Console Application


Step 3: We want an Empty project


Step 4: Done creating the project


This is what your project screen should look like at this point.


Step 5: Create a new item


Step 6: Create a C++ file, the name is your choice.


Step 7: Modify the project properties


Step 7: Select All Configurations


Step 9: Go to Configuration Properties / C/C++ / General / Additional Include Directories


Step 10: Enter the path to your include files: For default OpenCV install location, they are
"C:\Program Files\OpenCV\cvaux\include\";"C:\Program Files\OpenCV\cxcore\include\";"C:\Program Files\OpenCV\cv\include\";"C:\Program Files\OpenCV\otherlibs\highgui\";"C:\Program Files\OpenCV\otherlibs\cvcam\include\"



Step 10: Enter the path to your include files: For default OpenCV install location, they are
"C:\Program Files\OpenCV\cvaux\include\";"C:\Program Files\OpenCV\cxcore\include\";"C:\Program Files\OpenCV\cv\include\";"C:\Program Files\OpenCV\otherlibs\highgui\";"C:\Program Files\OpenCV\otherlibs\cvcam\include\"



Step 11: Go to Configuration Properties / Linker / Input / Additional Dependencies


Enter the path to all the relevant cv libs. For a default install, this is:
"C:\Program Files\OpenCV\lib\cv.lib" "C:\Program Files\OpenCV\lib\cxcore.lib" "C:\Program Files\OpenCV\lib\cvaux.lib" "C:\Program Files\OpenCV\lib\highgui.lib"
(notice the spaces instead of ; marks)


Write some code


Click on "Start Debug"


Hello World in OpenCV

Thursday, March 17, 2005

Switch to C++

I've decided to switch to C++, primarily because I like to use default parameters. For example, in the OpenCV 0.9.6 Documentation the Canny edge detector is defined as:

void cvCanny( const CvArr* image, CvArr* edges, double threshold1,
double threshold2, int aperture_size=3 );

That means that you can call cvCanny like this:

cvCanny(sourceimage, resultimage, low_threshold, high_threshold);

Or like this:

cvCanny(sourceimage, resultimage, low_threshold, high_threshold, aperature_size);

And either way will work in C++. C does not support this functionality. So, from now on, anything I post here probably won't compile like this:

gcc test.cpp -o test `pkg-config --libs opencv --cflags opencv`

But it will compile like this:

g++ test.cpp -o test `pkg-config --libs opencv --cflags opencv`

Even though the underlying program may be entirely C except for the OpenCV calls.

Documentation

Earlier, I had complained that the documentation for OpenCV that I could find easily was out of date. I was really looking for some kind of online reference, but it turns out the most up to date documentation is bundled with the distribution. It lives in a subfolder called (surprise) "docs". When you install OpenCV it puts these files by default in the folder /usr/local/share/opencv/doc/.

Opening the file index.htm gives you links to four reference files (OpenCV is really four separate libraries bundled together). The problem is, on my Linux machine, the links don't work. They don't work because the names of the files referenced by the link have capitals, where the actual filenames they reference are all lower case. I fixed this on my local machine and then decided I should put this fixed version online where people could get to it:

OpenCV 0.9.6 Documentation

Hopefully, this will allow for quick and easy reference (and as soon as google indexes it, a convenient site search).

Tuesday, March 08, 2005

My First OpenCV Program

Now that I've gotten OpenCV installed, the first thing I needed to try was to create a sample program of some kind that was basically not useful for anything except to demonstrate that I could compile an OpenCV program. Heres the code for test.c, my first attempt:

#include "cv.h"
#include "highgui.h"

int main( int arc, char ** argv)
{
int W = 640;
int H = 480;

// Images are stored in IplImage structs. The function cvCreateImage
// allocates space for an image of a certain type, in this case an
// 8 bit, 1 channel (grayscale) image.
IplImage *image = cvCreateImage(cvSize(W, H), IPL_DEPTH_8U, 1);

// Create a named window and show our image on it
cvNamedWindow("My First OpenCV Program", 1);
cvShowImage("My First OpenCV Program", image);

// Wait for any keystroke and then release the image from memory and exit
// the program
cvWaitKey(0);
cvReleaseImage(&image);
return 0;
}

All this code does is create a window and show an image of size 640x480 that was created using cvCreateImage. The image is black, which isn't surprising since we didn't put anything in it. In order to compile it from a shell I did:

gcc test.c -o test `pkg-config --libs opencv --cflags opencv`

How I Installed OpenCV

Thought I would start things off by recounting my installation experience. I'm running a pretty much default installation of Fedora Core 3 (I did install all the development packages, as well as gtk+2). I downloaded the Linux tar.gz from Sourceforge into my home directory and then from a shell did:

tar -xzf opencv-0.9.6.tar.gz
cd opencv-0.9.6
./configure
make
su -
make install
exit (to get out of root)

This all completed without any real trouble, and things looked good. Problem was, after this step I couldn't compile any opencv programs. One method for compiling an OpenCV program test.c is to type:

gcc test.c -o test `pkg-config --libs opencv --cflags opencv`

When I did this, pkg-config reported that it couldn't find opencv and that perhaps I should add opencv.pc to the PKG_CONFIG_PATH environment variable. I instead decided to add /usr/local/lib (the location of opencv.pc) to my /etc/ld.so.conf file and then run ldconfig (as root) to rebuild the links. You can check to see if everything is working by typing the following at the shell:

pkg-config --libs opencv --cflags opencv

which in my case returned:

-I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux

If you get this far, chances are you have everything you need to compile an opencv program except the source code.

Monday, March 07, 2005

Welcome

I've created this blog because I started experimenting with OpenCV and looking into it's enormous potential only to notice that the documentation is ... lacking. Even Google searches turn up less than impressive results, usually returning one of two sites:

University of Birmingham
A lecture with sample code
More comprehensive documentation

The Official Sourceforge Page
http://sourceforge.net/projects/opencvlibrary/

Admittedly, I've seen less documentation, but never on a project so large and well known. Even the documentation that exists, such as the sample code in the above link, doesn't compile without some modifications to the source. So as I run into problems and hopefully find solutions I'll post results here.