Feb 112013
 

There are a number of useful tools out there for writing computer vision software.  The three packages that follow are the ones that I have gotten the most use out of over the years.  These are very good tools, which I highly recommend to anyone that needs to create computer vision or image processing software.

Matlab Image Processing Toolbox

The Matlab Image Processing Toolbox is a set of functions in Matlab that support image processing and manipulation.  The toolbox provides the basic functionality to read in and write out images;  in recent years, this has expanded to video files as well.  Matlab treats images as matrices of pixel values, making great use of the first-class-citizen support Matlab gives to vectors and matrices.  Working with images at a pixel level is just like working with any other matrix in Matlab.

Matlab's great strength is it's ease of use for the programmer.  I sometimes joke that Matlab code is "executable pseudocode," and that is precisely the feel it gives while using it.  I can code up and try out more ideas, faster, in Matlab than I can in any other language.  Creating output plots, figures, and images is very straight forward, and makes checking code behavior a joy.  Unfortunately, there are some drawbacks to using Matlab--it's code can only run within the Matlab interpreter; it's dynamic record datatype is nice to work with, but there is no object-oriented support; and code executes very slowly (especially if you use any loops in your code, which is likely with image processing).

I find that my typical development workflow when developing computer vision algorithms will often start with creating prototype code in Matlab.  Once I get all of the mathematical and structural kinks worked out, I will sometimes then move on to implementing the code in C++ based on my completed Matlab functions.  Reimplementation in C++ is only done if I need real-time performance or faster testing.  If performance is no big deal, I find simply using my Matlab code to be acceptable.

OpenCV

The OpenCV C++ library is probably the most widely used computer vision library.  There is a lot in here from the low level to the high level.  The low level functionality to read in and write out video files is exceptionally useful, and the first step for someone just beginning to write vision software in C++.  OpenCV contains a plethora of higher-level vision code, from edge detectors through face detectors through machine learning algorithms.

OpenCV is very usable, and installation is very easy.  There is not much that has to be linked against, and the most widely used functions in it work really well.  It is an open source project though, and components that do not get much use can exhibit some wonky code.  It is pretty big, needing about 4 GB of space.  Overall, OpenCV is a great library and a good place to start for someone beginning to write vision code in C++.

VXL

The VXL C++ library is an amazing library, with vast functionality applicable to computer vision projects.  I am especially fond of the VNL and VNL Algos sub-libraries.  Honestly, they are the closest thing I have found to having Matlab's language-level support for matrices and matrix operations in C++.  This isn't to say the VXL library is as intuitive to use as Matlab, but VXL provides a lot of the functionality without having to write all the low-level matrix manipulation functions yourself.  What I find especially remarkable about VXL is that all of the code that I have had to go through in it has been very well written, which is not the case with all open source projects.

The major downside of VXL, in my opinion, is the building and installation process.  It is a serious rite of passage.  If you intend to use VXL for a project of yours, make sure to set aside a day (maybe two) to get to the point where you can link against it.  VXL is a library where only the source is provided, and it is up to you to get it compiled and working.  There are installation instructions on the VXL site, but they are not very detailed.  Here are some detailed VXL installation instructions that I have found to be useful.  It is important to also note that VXL is quite large; make sure to have about 10 GB free before you start with it.

Feb 112013
 

[The following are instructions that I have found to be incredibly helpful in getting VXL set up and working.  These instructions are a direct copy-paste of a blog post, which in turn seems to be a copy with some added detail of instructions used by a research group at Brown.  These instructions are not my words and not my work, and are posted here for educational purposes. -Nate]

 

BEGIN VERBATIM COPY

 

I’ve been working the last days with VXL, it is a collection of libraries for computer vision. It includes numeric, imaging, geometry, streaming and more libraries. When one started looking at the code impresses the amount of work people put into it. Also, it has a lot of good features and it is really easy to use, once you know how to compile it and the projects using it.

I struggle a few days trying to compile VXL itself and then linking the projects. Because of that I want to summarize a few tips to do it smoother.

Compiling VXL on Windows

I will describe the Windows steps, but if you are using other OS you can find some info here.

  1. First, you need to install
  2. First create a folder for the VXL libraries. For example, could be “C:\vxl” or whatever you want. Inside that folder create two more:
    • A sources folder “C:\vxl\vxl,” from now on $VXLSRC.
    • A binary folder “C:\vxl\bin,” from now on $VXLBIN.
  3. I download VXL from their site, but I have some trouble because the libraries were bugged. Therefore, I suggest you to use the SVN sources. So, lets check out the latest revision.
    • Right click on $VXLSRC, choose the “SVN Checkout” option.
    • In the “URL of repository” box, type in: https://vxl.svn.sourceforge.net/svnroot/vxl/trunk.
    • In the “Checkout directory” box, the folder path $VXLSRC.
    • In the “Checkout depth“, choose “Fully recursive.”
    • In the “Revision” box, choose “Head revision.”
    • Click “OK.”
    • Tortoise SVN should now download the souce code.
  4. Now, we need to prepare the Visual Project using CMake. CMake it is a tool that creates all the dependencies and resolve links necessary to build the sources.
    • Open CMake program (from Start menu).
    • In the “Where is the source” box, browse to $VXLSRC.
    • In the “Where to build the binaries” box, browse to $VXLBIN.
    • Click “Configure” (in bottom left of the window).
    • A window will show up, asking for the type of compiler. Choose the version of Visual Studio you’re using. Stay away from “Win64” option for now.
    • CMake will run a whole bunch of tests to determine the settings of the machine, compilers, packages, etc. The progress is shown in bottom of the window. This may take up to several minutes.
    • Once this is done, a window shows up, with a lot of red rows.
    • Scroll to find “BUILD_VGUI.” If it is unchecked,  check it. Click “Configure” again.
    • Scroll to find “VGUI_USE_MFC” (should be in red). If it is unchecked,  check it. Click “Configure.” If you can’t find this option, that means Microsoft Visual Studio was not installed properly. Ask someone.
    • Now the option “Generate” should be active, click it. CMake will now make all the “Projects” and “Solution” files for Microsoft Visual Studio in the $VXLBIN.
    • We finish with CMake for now, you can close it.
  5. Compile VXL code
    • Go to $VXLBIN.
    • Double-click on “vxl.sln.” This will open Microsoft Visual Studio.
    • From top menu, View –> Solution Explorer.
    • Right-click on “ALL_BUILD,” click on “Build.” This will build ALL projects in VXL. You can selectively build individual projects by right-click and “Build” that project, if you only need that one.
    • This process can take a while, up to a couple hours, depending on how fast the machine is.
    • After this is done, VXL is ready to use.

Using VXL on a project

Now that we compiled the libraries we can use them in our projects. There are two ways to use them (1) with CMake to create the project or (2) linking the libraries manually.

  1. Using CMake for the project. CMake is a tool that creates the projects and solutions for us. It support projects in Visual Studio.
    • First we should create two folders in the project folder. Similar to the steps when compiling VXL with CMake, one for the sources and one for the binaries, from now on I will call them $PRJSRC and $PRJBIN, respectively.
    • Now, we need to create a configuration file to tell CMake all the requirements we need. I will give here a basic one, for more details you can check here.
      01 # The name of your project. This will be the name of the solution
      02 PROJECT( test )
      03
      04 # Automatic setting of the VXL libraries
      05 FIND_PACKAGE(VXL)
      06 IF(VXL_FOUND)
      07   INCLUDE(${VXL_CMAKE_DIR}/UseVXL.cmake)
      08 ENDIF(VXL_FOUND)
      09 # Another option is to set the path directly:
      10 #   SET( VXL_DIR D:\vxl\bin )
      11
      12 # Here you tell to CMake which files to include
      13 IF( VXL_VGUI_FOUND )
      14   INCLUDE_DIRECTORIES( ${VXL_VGUI_INCLUDE_DIR} )
      15   SET( test_sources ${test_sources}
      16     # Put all your source code here: code and headers
      17     test.cpp
      18   )
      19 ENDIF( VXL_VGUI_FOUND )
      20
      21 # Specify the executable to be built
      22 ADD_EXECUTABLE( test ${test_sources} )
      23
      24 # Specify any other dependent libraries
      25 IF( VXL_VGUI_FOUND )
      26   TARGET_LINK_LIBRARIES( test ${VXL_VGUI_LIBRARIES} )
      27 ENDIF( VXL_VGUI_FOUND )<code>
    • Place the configuration file and all your source code in the $PRJSRC folder.
    • Open CMake and put the sources and destination folders to $PRJSRC and $PRJBIN, respectively (The steps are the same as the VXL compilation).
    • Click “Configure” button. The “Generate” button should be active afterward, then click it.
    • Now you can go to $PRJBIN and compile the project.
  2. If you don’t want to use CMake or you cannot use it because you have a project already, you need to include the libraries and link them manually.
    • In Visual Studio Tools–>Options, go to the “Projects and Solutions” option.  Then in that tree under “VC++ Directories” change the option “Show directories for:” and choose “Include files.” Then add the paths
      • $VXLSRC\vcl
      • $VXLSRC\core
      • $VXLBIN\vcl
      • $VXLBIN\core
    • Now, in the same place change the option “Show directories for:” to “Library files” and add $VXLBIN\lib
    • If you are using any non-core library you should add them too. For example, if you are using vsol in contrib/gel then you should add $VXLSRC/contrib/gel.
    • Click “OK.”
    • In the Solution Explorer, right-click to your project and choose “Properties.” Go to Configuration Properties–>Linker
    • Under “General,” in the option “Additional Library Directories” add $VXLBIN\lib\Debug
    • Under “Input,” in the option “Additional Dependencies” add vcl.lib, at least. Then link against all the libraries you used or the ones the compiler complains about. For example, if you use $VXLBIN\vil libraries add vil.lib, or if you use $VXLBIN\vil\algo libraries add vil_algo.lib.
    • Click “OK.”