Author: Antonio Cuni <[email protected]> Branch: extradoc Changeset: r3827:158b8e73b74b Date: 2011-07-07 17:11 +0200 http://bitbucket.org/pypy/extradoc/changeset/158b8e73b74b/
Log: small tweaks, and mention the video diff --git a/blog/draft/realtime_image_processing.rst b/blog/draft/realtime_image_processing.rst --- a/blog/draft/realtime_image_processing.rst +++ b/blog/draft/realtime_image_processing.rst @@ -6,13 +6,11 @@ in Python is foolish: Python is clearly not fast enough for this task. Is it? :-) -.. image:: sobel.png - 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, +``sobel.py`` implements a classical way of locating edges in images, `the Sobel operator`:http://en.wikipedia.org/wiki/Sobel_operator. It is an approximation of the magnitude of the `image gradient`:http://en.wikipedia.org/wiki/Image_gradient. The @@ -20,7 +18,7 @@ `convolutions`:http://en.wikipedia.org/wiki/Convolution between the image and 3x3-kernels. -magnify.py implements a pixel coordinate transformation that rearranges +``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. @@ -33,8 +31,8 @@ - `pypy-image-demo-full.tar.bz2`_: this archive contains both the source code and prebuilt PyPy binaries for linux 32 and 64 bits -.. `pypy-image-demo.tar.bz2`: http://wyvern.cs.uni-duesseldorf.de/~antocuni/pypy-image-demo.tar.bz2 -.. `pypy-image-demo-full.tar.bz2`: http://wyvern.cs.uni-duesseldorf.de/~antocuni/pypy-image-demo-full.tar.bz2 +.. _`pypy-image-demo.tar.bz2`: http://wyvern.cs.uni-duesseldorf.de/~antocuni/pypy-image-demo.tar.bz2 +.. _`pypy-image-demo-full.tar.bz2`: http://wyvern.cs.uni-duesseldorf.de/~antocuni/pypy-image-demo-full.tar.bz2 To run the demo, you need to have ``mplayer`` installed on your system. The demo has been tested only on linux, it might (or not) work also on other @@ -55,24 +53,26 @@ interpolation.`:http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation By adding the option -b, `bilinear interpolation`:http://en.wikipedia.org/wiki/Bilinear_interpolation -will be used instead, which gives smoother result. +will be used instead, which gives smoother result:: $ pypy demo/magnify.py -b There is only a single implementation of the algorithm in -magnify.py. The two different interpolation methods are implemented by +``magnify.py``. The two different interpolation methods are implemented by subclassing the class used to represent images and embed the interpolation within the pixel access method. PyPy is able to achieve good performance with this kind of abstractions because it can inline the pixel access method and specialize the implementation of the algorithm. In C++ that kind of pixel access method would be virtual and you'll need to use -templates to get the same effect. XXX: Is that correct? +templates to get the same effect without incurring in runtime overhead. -To have a feeling on how much PyPy is faster than CPython, try to run the demo -with the latter. These are the the average fps (frames per second) that I get -on my machine (Ubuntu 64 bit, Intel i7 920, 4GB RAM) when processing the -default ``test.avi`` video and using the prebuilt PyPy binary found in the -full_ tarball alinked above. For ``sobel.py``: +The video_ on the right shows PyPy and CPython running ``sobel.py`` side by +side (PyPy taking input from the webcam, CPython from the test +file). Alternatively, to have a feeling on how much PyPy is faster than +CPython, try to run the demo with the latter. These are the the average fps +(frames per second) that I get on my machine (Ubuntu 64 bit, Intel i7 920, 4GB +RAM) when processing the default ``test.avi`` video and using the prebuilt +PyPy binary found in the full_ tarball alinked above. For ``sobel.py``: - PyPy: ~47.23 fps - CPython: ~0.08 fps @@ -86,6 +86,7 @@ ``magnify.py`` the difference is much less evident and the speedup is "only" 15x. +.. _video: http://www.youtube.com/watch?v=5DtlBC_Zbq4 .. _full: http://wyvern.cs.uni-duesseldorf.de/~antocuni/pypy-image-demo-full.tar.bz2 It must be noted that this is an extreme example of what PyPy can do. In _______________________________________________ pypy-commit mailing list [email protected] http://mail.python.org/mailman/listinfo/pypy-commit
