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!

4 thoughts on “pyblobs with OpenCV 2.1 on Ubuntu 11.10

  1. Hi! Interesting article! However, it is quite common nowadays to use OpenCV 2.3.1, often from PPAs such as this one:

    The method you have advised does not seem to work any more, because it looks for libcv, whereas now it is libopencv-dev. Any suggestions on how I can make it work with OpenCV 2.3.1?

  2. thanks a lot for this post! it was very helpful for me.

    btw: I had to install a few extra packages to get this to work (libcvaux-dev, libhighgui-dev, gtk2.0, at least). also, I had to change `pkg-config –libs opencv` into `pkg-config –libs opencv –cflags`, so g++ would know where to find the library. do these look like changes you should incorporate into your patch?

  3. Hi,

    I want to include pyblobs library in windows. I am using Python 2.7 and OpenCV 2.4. Can you help?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.