Realtime image processing in Python
Originally published on the PyPy blog.
Image processing is notoriously a CPU intensive task. To do it in realtime,
you need to implement your algorithm in a fast language, hence trying to do it
in Python is foolish: Python is clearly not fast enough for this task. Is it?
:-)
Actually, it turns out that the PyPy JIT compiler produces code which is fast
enough to do realtime video processing using two simple algorithms implemented
by Håkan Ardö.
sobel.py implements a classical way of locating edges in images, the
Sobel operator. It is an approximation of the magnitude of the image
gradient. The processing time is spend on two convolutions between the
image and 3x3-kernels.
magnify.py implements a pixel coordinate transformation that rearranges
the pixels in the image to form a magnifying effect in the center.
It consists of a single loop over the pixels in the output image copying
pixels from the input image.
You can try by yourself by downloading the appropriate demo: