[PyQt] PyQt and image processing

Gerard Vermeulen gav451 at gmail.com
Sat Apr 12 14:21:58 BST 2008

On Sat, 12 Apr 2008 02:16:58 -0300
"Laura X" <lxlaurax at gmail.com> wrote:

> Dear PyQt experts,
> I am choosing a GUI toolkit for developing an application
> (cross-platform) and PyQt seems to be simpler/more-intuitive for
> programming than others. My application will have some basic image
> processing (transformations, filtering, pattern recognition (e.g.,
> with convolution), etc., but nothing complex) and some
> drawing/painting on image stuff (I am also interested in playing an
> AVI movie and transform each frame in single image inside my
> application).
> Pardon my ignorance but searching on the internet I was unable to find
> examples of applications or descriptions of these functionalities in
> PyQt.
> I saw that PyQt has some nice built in functions for more basic image
> processing but nothing on filtering and pattern recognition (e.g.,
> with convolution).
> It would be OK if I could use PIL or OpenCV for these stuff but it
> seems the PIL integration in PyQt is somewhat limited or at least the
> image conversion is too slow and there is nothing on OpenCV.
> So, are there PyQt applications/examples on image processing? Using
> PIL or OpenCV? Is it possible to load an AVI file and process the data
> in PyQt?
> Of course I understand that if there aren't good app's this does not
> mean it is not possible to develop, but I want to learn with the
> experience from others.
http://effbot.python-hosting.com/file/pil/PIL/ImageQt.py shows how to
convert a PIL image to a QImage using a Python string to exchange the
It is also very easy to convert the data in a QImage to a Python string.
For instance
>>> image = QImage(256, 256, QImage.Format_ARGB32)
>>> bytes = image.bits().asstring(image.numBytes())
>>> len(bytes)
262144 # == 4*256*256
I suppose that it is easy to convert from a Python string to a PIL
image.  The penalty of using a Python string instead of copying
directly by means of a Python extension written in C or C++ is that
the data is copied twice instead of once.  It depends on the resources
required by your image processing if that is significant or not.

It looks that OpenCV has much more image processing capabilities than
PIL.  A bit of googling (search for numpy and OpenCV) shows that OpenCV
contains a file adaptors.py which allows to convert between OpenCV/IPL
images, PIL images and numpy arrays.  All those conversions use Python
strings as an intermediate format.
( http://opencvlibrary.cvs.sourceforge.net/opencvlibrary/opencv/interfaces/swig/python/adaptors.py?view=markup )

Anyhow, if you need PIL or OpenCV with another GUI toolkit, you have
to convert to and from the image format of the other toolkit.

I think that http://pymedia.org/ lets you convert AVI (and other) movie
frames to strings.

Regards -- Gerard

More information about the PyQt mailing list