pyblobs with OpenCV 2.1 on Ubuntu 11.10

pyblobs is a Python interface for cvBlobsLib. To use it with OpenCV 2.1 on Ubuntu 11.10 follow these steps.


The following dependencies are required to use pyblobs library:

sudo apt-get install swig
sudo apt-get install libcv-dev
sudo apt-get install python2.7-dev
sudo apt-get install python-opencv

If you are using Python 2.6, then use sudo apt-get install python2.6-dev instead.

Getting the pyblobs library

Use svn to grab the source code

cd /path/to/Downloads/
svn checkout pyblobs-read-only

Patching the files

The code from the trunk as of now uses Python 2.5 (python2.5-dev) and not the best way to link shared objects in the file. There is another issue with building the pyblobs library to be used with OpenCV 2.1 in the file BlobExtraction.cpp

Hence, I have created two patch files for the aforementioned files:

Download these to the same directory as the downloaded library (pyblobs-read-only) and then run the following commands in the terminal:

cd /path/to/Downloads/pyblobs-read-only/
patch make_swig_shadow.patch
patch BlobExtraction.cpp BlobExtraction.patch

If you are using Python 2.6, then after patching edit and replace any occurennces of python2.7 with python2.6 .


To install


To check your install, go to your Python shell and try the following imports:

>>> from blobs.BlobResult import CBlobResult
>>> from blobs.Blob import CBlob

If all goes well, you shouldn’t see any errors. Now you can work with pyblobs and OpenCV2.1 on Ubuntu 11.10!

That said, to get the example file working, you might need to modify it a little to use objects and methods from the newer OpenCV Python API. For example, in my programs I replace

from opencv import cv
from opencv import highgui

with import as cv to use the new API as cv.MethodName() instead of cv.cvMethodName() or highgui.cvMethodName(). Makes life a lot easier!

Posted in Computer Vision, Python | Tagged , , | 4 Comments