coding gems and personal insights in the electronic age, by nic werneck

Journey through a two-tone corridor

This article brings a Python code, with and without numpy, to generate a video of a camera moving down an infinite two-tone rectangular corridor, with a checkerboard pattern (with quite large panels).

When I started to code for real, what I did was “demos”. Those small programs that produce cool animations. I never did nothing too fancy, just basic Computer Graphics stuff like translucent rotating cubes. I started with Pascal (yuck!) and then moved to C… Today I use mostly Python, and I work with Computer Vision what is more or less the opposite of Computer Graphics. While CG is concerned with producing images from a given model, CV tackles the inverse problem of figuring out what model would produce that image. Or images, in the case of analyzing a video.

It is useful in CV research to have simulations made with CG so we can test our programs with a known model, to check our answers and debug the systems starting way back at the image processing steps. I have just finished creating a program, and found myself needing some artificial images to make a test. I needed a video of a camera moving along a corridor while its orientation and position changes slightly in time. And the corridor needed to have edges on the directions of the coordinate axes (x, y, z, i.e. vertical, horizontal and “along the corridor” directions).

So I settled to make that in Python… This is simple because it requires nothing fancy such as complicated textures, illumination models, ray tracing… The only complicated thing is to understand all the geometry stuff, know about camera models, perspective, rotation matrices, etc. Here is one frame produced by the program. Of course, you can also watch the final video, on YouTube.

So, without further ado, here is the code. It is commented, but if anyone has any questions, feel free to ask!