Monday, February 28, 2011

[Py] Use cProfile to check the run time performance of a program

When I was trying to figure out the usage about get_fps of pygame.time.Clock, I read about the thread:

And I noticed that they were talking about ``cProfile,'' so I went to the document about it:

[Py] Using get_fps function of pygame

There are modules of pygame which provide time related functions. One of them is the get_fps which can be used to know the fps of executing program.

Using rst files -- the easy way

When viewing documents of mahatos, there are text files with rst as their extensions. They reminded me about the reStructureText which I met but got confused and gave it up. This time I tried to figure out how to use it and how to convert it into other formats, for example, the HTML. The following steps and links are my quick notes, just for you who also want to try the rst files very quickly on Ubuntu.

  1. Assume that you have Python on your system already.
  2. $ sudo apt-get install python-docutils (this is the module that gives the utilities of the conversion between rst and other formats)
  3. Download the source package of Docutils
  4. Untar the downloaded package and go to the tools directory, find the rst2html.py, and copy it to a folder contained the cheatsheet.txt (Please download it. It is a text file formatted in rst file, and we will use it for the following test.)
  5. Go to the folder contained the cheatsheet.txt file
  6. $ python rst2html.py cheatsheet.txt cheatsheet.html
  7. You now have the cheatsheet.txt converted to cheatsheet.html, and you can view the cheatsheet.html in your browser
To be brief, use the the tools given by the source package to convert the rst text files into other formats.

Before jump into installing the Dcoutils on your system, you may want to try and see the rendered result online: reST to HTML conversion. Just copy the content of cheatsheet.txt and paste it into the online converter, and click the Render button to view the result. That's pretty cool. :-)

    [Py] SURF tests with mahotas.surf

    I installed mahotas in my Python for the purpose of trying the SURF. There is a simple example on the mahotas document page, but some minor modifications are needed. Here is the modified example code:

    Sunday, February 27, 2011

    Installing Mahotas (image processing in Python)

    I've just learned about SIFT and SURF, and am trying to find some example to learn more.

    For SIFT, it is a patented methodology and seems not possible to be used as the open sourced libraries. For SURF, which has been claimed more robust and faster then SIFT, there is OpenSURF written in C++.

    Based on the information given on Wikipedia, I went for mahotas, which is for image processing in Python, and that's what I need.

    Saturday, February 26, 2011

    [Py] Python+OpenCV+pygame for capturing webcam frames on Ubuntu (10.04)

    Several weeks ago, I tried to find some sample code which can get the frames of the webcam on Ubuntu. Some examples were written in C/C++, some were in Python, and them are all based on OpenCV. I tested them and got some failed. Unfortunately, I have neither enough experience nor enough time to figure out where the problems are, so I started to search some more examples again.

    The first light came from Joseph Perla's blog. He gave an example which worked fine on my Ubuntu 10.04. I post the example with minor modifications (using ImageOps.mirror to flip the image horizontally) as the follows.

    Friday, February 25, 2011

    Stereo vision -- source code testing


    C. Zitnick and T. Kanade proposed an algorithm [1] to compute the depth (or disparity) maps for stereo version. The source code was released for non-commercial usage, and there is a modified version by K. Sokolova and B. Shilo. I suggest you go for the modified version which gives some practical and straightforward descriptions and examples. Also, the modified version offers a complete set to be compiled and executed. However, the source code needs some more minor modifications to be compiled using g++ in Ubuntu 10.04.

    Friday, February 18, 2011

    Bring good stuffs of Linux into Windows

    I love to work with Linux (Ubuntu), especially with its useful commands and tools when I need to write programs or analyse some kind of data. Sometimes, however, I have to cooperate with my colleagues, who are working with Windows and Visual Studio. Maybe I can do the coding works in Ubuntu, but I am not so good to solve all the problems related to hardware and drivers. We are always using cameras to capture images and process the streams in real-time. There are problems for me to run all the programs written by my colleagues in Ubuntu, and unfortunately I have no enough time as well as knowledge to tackle all the problems. Therefore, I have to go back to Windows for some program developments.

    But, the command line environment in Windows is not so convenient as in Ubuntu. Lacking the useful commands and tools might be the most inconvenient. Cygwin is one way to run Linux commands in Windows, but it can only work within the Path in which the Cygwin is installed. Luckily, we have GunWin which provides many of the useful tools for Windows. Just click the ``Setup'' links on the page of  packages, then you will get the tools installed and you can use them directly in the Windows cmd shell.

    For further introduction, please go for the following link:

    Moved from Firefox to Chromium

    I have moved from Firefox to Chromium for several weeks. Firefox is excellent in many aspects, especially its abundant and wonderful add-ons. However, in my own experience, it is not really fast. After some trials and findings, I decided to use Chromium as my default browser.

    I would like to share some experiences here. Some are the excellent features of Chromium, and of course some are not so good.

    Thursday, February 17, 2011

    codepad -- an interesting web service for code sharing

    Check the codepad out. I had no idea about pastebin until meet the codepad website. It's really useful when you want to share some code and output with someone via email, MSN, or other internet media.

    Here is my simple trial on the codepad: http://codepad.org/Oja9hsaI

    Saturday, February 05, 2011

    VirtuaWin -- Virtual desktop manager for Windows

    If you are used to working with virtual desktops or workspaces in Linux, you might feel uncomfortable when working under the Windows environment. Fortunately, VirtuaWin offers an wonderful solution. I have used VirtuaWin in my office PC for at least couples of month. Today I have to do some works in Windows in my laptop, recalled VirtuaWin, and I think this time, I should introduce this good applications to you who read this post. In addition to its excellent functions, VirtuaWin is licensed under GNU.

    After downloading VirtuaWin and installing it, you can check the content of Setup by right clicking on the icon of VirtauWin, which should reside in the bottom right toolbar of the desktop.

    Basic usage by default:
    Alt+Ctrl+Left/Right/Up/Down: to navigate around the virtual desktops
    Alt+Win+Left/Right/Up/Down: to move the working window to the next virtual desktop

    ---
    Note: Its name is VirtuaWin, not VirtualWin.