Tuesday, May 31, 2011

Tile Figures with Montage (ImageMagick)

Suppose you have several figures for articles ,papers, blogs, or anything else. You want to combine these figures into a bigger frame, and they have gaps between each other. How? I had used Inkscape to import the figures, arrange them, and export the final result. No, don't do that again. It is not necessary to launch your image editors with GUI to accomplish this kind of work. I found the most convenient  way is to use some commands offered by the magic ImageMagick.

Good examples have been given in ``ImageMagick v6 Examples -- Montage, Arrays of Images,'' and the following is my own test with some notes.

Sunday, May 22, 2011

Tetris in Command Line

Ha ha! That's really funny. I never think about even sed can be used to write games such as Tetris!

I just wondered how to play Tetris in command line. Googled it and found several results with source code. There are three of them I've played:
  1. Tetris for the command line with Python Curses (in Python)
  2. Play Tetris at the command line (in sed)
  3. tt: Tetris for Terminals (in C)
To compile tt, you may need to install ncurses, or you will get the following errors:
utils.c:32:20: error: curses.h: No such file or directory
utils.c:33:18: error: term.h: No such file or directory

In Ubuntu, just install the ncurses-dev.

Thursday, May 05, 2011

[talk] Thanks to You

I attended a class about how to write English emails yesterday. At the end of the class, the lecturer asked us to write an email for exercise. Below is what I wrote. A personal thank to you who have contributed to the open source community.

Dear Mr. and Ms. Hackers,

I am writing to thank you for your great and amazing works
to the open source community.

With so many brilliant tools you've created and kindly released,
many end-users, including me, are allowed to do more useful
things with free [of] charge and, more important[ly], with the freedom
to choose software.

Furthermore, I've learnt about many interesting and useful skills from
the source code released by you.
That's great and I hope I could be capable of contributing back to the
community in the future.
Thank you all for your great works.

Sincerely yours,


THK

Thursday, April 28, 2011

Great tool for LaTeX users working with MS Word -- Bibtex4Word

I was writing conference papers which have only templates in MS Word, and was wondering how to cite the references and to produce the bibliography in Word as easy as that in LaTeX. Then I found Bibtex4Word.

Most MS Word users might type the bibliography list manually, and it is really a tedious work. Inconsistent formatting style might be a main problem of manually typing the bibliography. The format should be done automatically, and should be changed easily to other styles. Just all the natural things in LaTeX.

Bibtex4Word can do the work pretty nice. I have installed and tested with it. Other programs needed are:
  • JabRef: to produce and to manage the bib file of your references
  • MikeTeX: to provide BibTeX for Bibtex4Word so that it can output formatted bibliography list
No need to worry about the formatting is really great. :-)

Wednesday, April 20, 2011

[talk] Talk to myself...

  • Work hard when you are at work.
  • Don't promise too much, but once promised, don't think too much. Just do it.
  • No matter what is in front of you, calm down.
  • The only way to solve the problem is to solve it.
  • A problem is not only a problem, it's also a challenge, and could be a chance, an opportunity.
  • Knowledge, skill, and working hard.

Tuesday, March 08, 2011

[Py] Use ``import cv'' in Ubuntu

At the beginning of my OpenCV learning with Python, I noticed one thing which confused me but I didn't give it further attentions. Some examples import the OpenCV modules by using ``import cv'' and some use ``import opencv.'' The first one has never worked to me, so I've adopted ``import opencv'' until today.

The problems were not only about the import approach. Although I found I can import opencv.cv module, which looked similar to the so-called cv module, there had been other problems about the function names. I noticed that many functions given by the opencv.cv module have the ``cv'' prefix, while the same functions given directly by the cv module don't. For example, opencv.cv offers open.cv.cvSomeFunction() while in cv it is cv.SomeFunction(). Based on the observation, I suspected that my installation of OpenCV an/or Python bindings are not totally right.

Thursday, March 03, 2011

Trials of pycam example code (2)

I've downloaded pycam and tested some of the sample codes. There were some errors when I tried to run the examples, such as DrawAHat.py and eyeLocator.py [1]. The error messages were as follows.

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.

    Wednesday, January 26, 2011

    Trials of pycam example code

    I am trying to learn something about computer version, and Python is my first choice of the coding tool. After several hours of searching, I found pycam. There are several sample codes given by the pycam. What I have downloaded was the ``pycam-read-only'' folder in which are three subdirectories:

    • c-vs-py
    • openeyes
    • pycam

    To install the pycam, just find the ``setup.py'' in the subdirectory named ``pycam'' and run ``sudo python setup.py install.'' Furthermore, what you need to install might include the follows:

    • python-opencv
    • python-pygame
    • libcv-dev
    • libcvaux-dev
    • libhighgui-dev

    The lib*-dev are (my guess) for the cpp codes, which need to include the cv.h and highgui.h.

    So far, my testing results are:

    1. pycam-read-only/pycam/examples/: Okay, but the fps are low
    2. pycam-read-only/pycam/examples/opencv: Failed. There were errors I don't know how to resolve yet. Only the ``cam-histo.py'' can be executed, after remove the ``cv.CV_VERSION'' at line 88. (the CV_VERSION seems not in my OpenCV.)
    3. pycam-read-only/pycam/pycam/: Failed
    4. pycam-read-only/c-vs-py/c_examples: Okay
    5. pycam-read-only/c-vs-py/py_examples: Some codes showed errors. They are harris_opencv.py, objectDetect.py, and people_only.py.
    ---
    EDIT: New results are given in the new post:
    Trials of pycam example code (2)

      Tuesday, January 25, 2011

      Face detection-- code patch and tests with some drawings

      My colleague introduced me an OpenCV site in Japanese in which many sample codes are available. Most of the sample codes are written in C++, and some are converted to Python also. I copied one sample code, which is used for face detection.

      After testing, I found the sample code has two lines which have to be modified to run properly. The first one seems to be a typo. The variable named as ``storage1'' should be ``storage'' according to other lines of code. The 25th line with variable ``starage1'' should be deleted. Another modification is to change assign the path of Haar-cascade xml files [*] explicitly. The original code gives the xml file without the complete path, and the program cannot find the so-called ``haarcascade_frontalface_default.xml.''

      The patch file:
      @@ -22,9 +22,8 @@
                       sys.exit(-1)
               src_gray = cvCreateImage(cvSize(src_img.width, src_img.height), IPL_DEPTH_8U, 1)
       
      -        storage1 = cvCreateMemStorage(0)
               ## (2)ブーストされた分類器のカスケードを読み込む
      -        cascade_name = "haarcascade_frontalface_default.xml"
      +        cascade_name = "/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"
               cascade = cvLoadHaarClassifierCascade(cascade_name, cvSize(1,1))
       
               ## (3)メモリを確保し,読み込んだ画像のグレースケール化,ヒストグラムの均一化を行う
      
      


      Here I tested the sample code with some of my drawings, which can be viewed on my another blog. The results are interesting (at least for me).









      ---
      [*] I have just begun to learn things about computer vision, so I might use some terms wrong.