First practical session: introduction

Goal

The goal of this session is to make you comfortable with Python and the combination of Python with C++.

The practical assignments must be made in a combination of Python and C++. We assume that you have general programming skills, basic knowledge of C++ and no knowledge of Python. You will be provided with bits of Python/C++ example code to give you a quickstart. In this practical session, you can follow the next instructions to learn how to program in Python and how to use the example code. Following these instructions is facultative but recommended.

First hour: learn Python

Python is easy to learn, easy to use, makes programming take less time and more fun. To start learning, (quickly) read and/or try the Python crash course. Start at "Interactive" and stop after one hour.

Second hour: learn to combine Python and C++

Python is great but it has a weakness: 'for-loops' are slow. Therefore, for operations on pixels, we will use C++. These instructions illustrate how to combine Python and C++.

In the following instructions, several directory names are suggested, but you may use alternative directories if you insist.

Step 1: Get the introduction files

Step 2: Get a sample image

Step 3: Try the introduction files

Step 4: Understand the introduction files

If you are finished early, you are suggested to start working on Assignment 1.


Appendix: Description of the files

Files in introduction/

FileDescription
croplib.cppCrop p*m images.
croplib.hHeader for croplib.cpp.
croplib.iInterface between C++ and Python for croplib.
example-crop.pyShows how to use croplib. Crops an image.
example-featextract.pyShows how to use featlib. Computes a simple feature vector containing one value: the fraction of dark pixels.
featlib.cppExample feature extraction code: computes the fraction of dark pixels.
featlib.hHeader for featlib.cpp
featlib.iInterface between C++ and Python for featlib.
MakefileInstructions for 'make' to compile the code.

Files in toolbox/

FileDescription
pamImage.cppRead and write .pbm/.pgm/.ppm files (black/white, grayscale, color respectively) (you don't need to look inside this file).
pamImage.hHeader for pamImage.cpp; look here to see what you can do with a PamImage object.
pamImage.iInterface between C++ and Python for pamImage.
word.pyObject for word zones and transcription (needed for later assignments).
wordio.pyReads and writes .words files (needed for later assignments).
wordsline.pyObject for text line zones and associated word zones (needed for later assignments).

The .i files define an interface between C++ and Python. Swig uses them to create a Python wrapper around the C++ code.


Last modified: 8 May 2009, by Axel Brink.