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

Saturday, April 16, 2005

cvReleaseImage() on image with ROI set

This one took me a long time to track down, so make sure you clear an image's ROI before you call cvReleaseImage() on it. The error I kept getting (which of course is very informative) was:

OpenCV ERROR: Unknown error code -49 (Deallocation error)
in function cvFree, cxalloc.cpp(136)
Terminating the application...

cvIntegral() on 32-bit floating point images

OpenCV provides a very useful function performing fast Viola and Jones object detection, but it can be a little silly in its requirements for the target image format. For the most part, it insists on you using double precision floating point integral images, and if you need to store a whole bunch of these in memory, you can quickly run out of RAM even on well equipped modern machines. Not finding an easy way to force it to use floats instead of doubles, I wrote my own integral image function, which frankly, looks simpler than OpenCV's, which you are free to use:

http://www.etalonsoft.com/code/integral.cpp

Tuesday, April 05, 2005

Montage in OpenCV

MATLAB has a really convenient function to create a montage of images -- i.e. a large image from a whole bunch of little ones. Requiring this functionality in my OpenCV projects, I decided to write my own utility function that accomplishes the same goal. Here's the code for it, and below is an example montage image produced:


Example montage image with 10 images per row

Saturday, March 19, 2005

OpenCV Assertions Are Lame

Whenever OpenCV library functions encounter a problem such as a NULL pointer passed in, or unexpected dimensions, or unexpected image format, they croak right away and for your help, apparently, output a line number deeeep inside the function framework where the problem occurred, which is often of little use to you. Here's an example:

OpenCV ERROR: Null pointer (NULL array pointer is passed)
in function cvGetMat, cxarray.cpp(2766)
Terminating the application...

If you're compiling on the command line, you'll have to bust out gdb and hope you're a gdb pro to find what high-level function call in your code causes the assertion to fail.

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.