OpenCV for iPhone

Author:nick @ May 22nd, 2009 Comments Off

Here are directions for compiling OpenCV libraries that are suitable for the iPhone:

http://ildan.blogspot.com/2008/07/creating-universal-static-opencv.html

Unsigned Image Comparison in Matlab

Author:nick @ March 10th, 2009 Comments Off

I was recently doing something like the following in Matlab:

im1 = imread(’im1.jpg’);

im2 = imread(’im2.jpg’);

if sum((im1(:)-im2(:)).^2) < 1e-5, disp(’Image 1 and 2 are duplicates!!!’), end

So the point of these three lines of code is to compare image 1 and image 2, and if they are sufficiently close (exactly or nearly exactly), call them duplicates.

The preceding code has an interesting non-obvious bug:  For integer-valued jpgs, Matlab loads them as type uint8. The above test will be passed not only if all pixels are the same, but also if every pixel in im2 is brighter than every pixel in im1. This is because, with unsigned integers, 1-2 = 0.

So I had a very washed out image in my image set that was testing as a duplicate of many images, just because nearly all pixels in the saturated image were 255, and x-255=0 for all unsigned x.

OpenCV Mac Programming

Author:nick @ October 22nd, 2008 Leave a Comment

There are currently at least two easy ways to acquire and use OpenCV libraries under OS X. One is to download the OpenCV framework from:

http://www.ient.rwth-aachen.de/~asbach/OpenCV-Private-Framework-1.1.dmg

This provides a set of precompiled, binary, static, universal libraries that can be easily integrated with XCode, and can be used to generate stand-alone mac applications.

The second is to use MacPorts to install OpenCV via “sudo port install opencv” from your terminal after MacPorts has been installed and updated, via “sudo port selfupdate”. This currently intalls OpenCV 1.0 rather than 1.1. This will download and compile source code for opencv and all of its constituent parts. Linking is done dynamically via dynamic libraries (.dylib), and /opt/local/lib must be in your dynamic library path. Some libraries here, e.g. libjpeg, seem to conflict with native OSX libraries, which should be given preference. To avoid these conflicts, use “export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib” rather than using the DYLD_LIBRARY_PATH variable directly.

For the sake of preserving compatility during development, the more unix-like approach of the MacPorts version should be preferred because similar environments can easily be emulated directly on Linux and in Windows via Cygwin. For demo purposes it may be nice to have the ease of access of applications afforded by XCode.

I have noticed some incompatiblity between the code I developed under XCode and the same code compiled through a console using dynamic libraries. I have not yet determined if this is due to the difference between OpenCV 1.0 and 1.1, or something more subtle. I am still investigating. Again for compatibility reasons, it is probably preferable to develop for OpenCV 1.0 unless absolutely necessary. Any software that we develop that for any reason *requries* OpenCV 1.1 should be explicitly documented as such. If the incompatibilities I have noticed are due to something other than version, then we must be very careful to instruct users how to set their OpenCV environments to be compatible with our software.

Introducing OpenCV Tips/Tricks Tutorials

Author:nick @ October 22nd, 2008 Leave a Comment

We are beginning a section of the MPLab blog to maintain a knowledgebase for the expertise we gain as we adapt our existing Machine Perception solutions to be more compatible with the OpenCV platform.

Matlab ’sample’ function

Author:nick @ January 30th, 2008 Leave a Comment

I recently discovered Matlab’s “sample” function, which I have implemented on my own several times before. There are always slightly annoying implementation details to work out, and it’s very nice to have a function that is standard to do it for me.

The idea is to sample from a multinomial distribution, which is something you need to do from time to time for various reasons. Here is an example of usage:

>> sample([.25, .5, .1, .15],1),  ans =  3
>> sample([.25, .5, .1, .15],1),  ans =  4
>> sample([.25, .5, .1, .15],1),  ans =  1
>> sample([.25, .5, .1, .15],1),  ans =  4
>> sample([.25, .5, .1, .15],1),  ans =  2
>> sample([.25, .5, .1, .15],1),  ans =  1
>> sample([.25, .5, .1, .15],1),  ans =  2
>> sample([.25, .5, .1, .15],1),  ans =  2

a = sample([.25, .5, .1, .15],10000);
>> nnz(a == 1),  ans =  2483
>> nnz(a == 2),  ans =  5027
>> nnz(a == 3),  ans =  988
>> nnz(a == 4),  ans =  1502

Linear Dynamical Systems Course

Author:nick @ December 28th, 2007 Leave a Comment

Stephen Boyd teaches a Linear Dynamical Systems course at Stanford. The course webpage is

http://stanford.edu/class/ee363/

The lecture notes are excellent, and are recommended for anyone interested in a crash course in Linear Dynamical Systems topics (LQR, Kalman Filter, etc.) Here is a list of topics covered:

1. Linear quadratic regulator: Discrete-time finite horizon
2. LQR via Lagrange multipliers
3. Infinite horizon LQR
4. Continuous-time LQR
5. Invariant subspaces
6. Estimation
7. The Kalman filter
8. The extended Kalman filter
9. Conservation and dissipation
10. Basic Lyapunov theory
11. Linear quadratic Lyapunov theory
12. Lyapunov theory with inputs and outputs
13. Linear matrix inequalities and the S-procedure
14. Analysis of systems with sector nonlinearities
15. Perron-Frobenius theory

Begin Blog for MPLab Tutorials

Author:movellan @ July 18th, 2007 Comments Off

Today we begin the blog for the MPLab Tutorials. Hope for it to be a good way to get feedback and help refine the tutorials.