pyblobs is a Python interface for cvBlobsLib. To use it with OpenCV 2.1 on Ubuntu 11.10 follow these steps.
Prerequisites
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 http://pyblobs.googlecode.com/svn/trunk/ 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 make_swig_shadow.sh 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.sh make_swig_shadow.patch
patch BlobExtraction.cpp BlobExtraction.patch
If you are using Python 2.6, then after patching edit make_swig_shadow.sh and replace any occurennces of python2.7 with python2.6 .
Installation
To install
make
./make_swig_shadow.sh
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 demo.py 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 cv2.cv as cv
to use the new API as cv.MethodName() instead of cv.cvMethodName() or highgui.cvMethodName(). Makes life a lot easier!
Hi! Interesting article! However, it is quite common nowadays to use OpenCV 2.3.1, often from PPAs such as this one:
https://launchpad.net/~gijzelaar/+archive/opencv2.3
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?
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?
Great article!!!!!
Hi,
I want to include pyblobs library in windows. I am using Python 2.7 and OpenCV 2.4. Can you help?