Jonathan. Frech’s WebBlog

Curses Cam (#139)

Jonathan Frech,

Normally a shell lets you input via a text command and outputs via a text message⁠¹. When using curses you can extend its capabilities and pro­gram for example games with limited graph­ics.
I wanted to go even further and built a Python script that — using Pygame’s camera module and curses — captures an image from an at­tached webcam (USB or built-in), transforms it and displays it on the shell.
Al­though both the resolution and the color depth are shrunk immensely, the resulting colored text on the shell often resembles the scene caught and has a nice visual ef­fect.
There are two modes, camera and file viewer, which can be toggled by pressing “F1”. In camera mode you can see what the camera is seeing and snap a photo, which then will be saved to disk. In file viewer mode you can view the photos you took. The files will be saved in an out/ directory located in the cur­rent Python file’s directory. Saved photos have the file extension .si (“shell image”).
Un­for­tu­nate­ly, Pygame’s camera module does nei­ther work on Mac OS X nor on Windows. Thus this pro­gram is on­ly properly usable under Linux⁠² sys­tems. You obviously also need a webcam or else you will not be able to take a picture.

Controls

Source code: curses-cam.py


[1][2020-07-20] Technically, that is a command prompt used to interact with a terminal.
[2][2020-07-20] GNU/Linux!