Project Polascii - Supported by SZDIY
       ___      @@@@@@@@   @@@@@@  @@        @@@@@@@   @@@@@@@  @@@@@@  @@@@@@@@@ @@@@@@@@
     _/[ ]\_    @@     @@ @@    @@ @@       @@     @@ @@       @@    @@     @@       @@
    |       |   @@@@@@@@  @@    @@ @@       @@@@@@@@@  @@@@@@  @@           @@       @@
    |  (O)  |   @@        @@    @@ @@       @@     @@       @@ @@    @@     @@       @@          (8)
    |_______|   @@         @@@@@@  @@@@@@@@ @@     @@ @@@@@@@   @@@@@@  @@@@@@@@@ @@@@@@@@   ++ \\|// ,,,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

polascii-display

POLASCII project contains two versions: an Raspberry Pi version and a PC version.

字符拍立得(POLASCII)项目包含有两个版本:一个树莓派版和一个PC版。

In the beginning, I was thinking using Raspberry Pi to make a hacking project to demonstrate on Maker Faire Shenzhen 2014. When dyne's hasciicam project came to my eyes, I thought about the idea of a combination of ASCII camera and a Polaroid, which can also get user an ASCII photo instantly. So on the Hack42 hackathon, I tried out a few things that I might be using: Raspberry Pi, RPi camera, the thermal printer, and the AA-lib.

最初的时候,我的设想是用树莓派制作一个项目参加2014”深圳制汇节“的展览。当我看到dyne的hasciicam项目时,我慢慢地想到了要将字符画和拍立得结合在一起的主意,这样用户就可以马上拿到一张字符风格的照片回去。于是在一场Hack42黑客马拉松里,我就把这个项目的可能会用到的技术都测试了一下:树莓派,树莓派摄像头,热敏打印机,AAlib。

It's easy to use Debian on Raspberry Pi, so all I need to do is to find the library for capturing pictures from the camera, render them into ASCII characters, and then send to the thermal printer to print. On Raspberry Pi, there is a picamera for it's specific camera. For the thermal printer, there is this python-escpos project which handles the printing interface. And the last, there is also this python-aalib which wraps up the C interface of linux aalib.

在树莓派上跑起Debian操作系统是很轻易的,接下来我需要做的便是要找齐这些功能相关的库:从摄像头拍摄照片的,将照片渲染成字符画的,将字符画发送到热敏打印机打印的。在树莓派上,有一个叫做picamera的库可以控制摄像头的拍照或视频;而热敏打印机则可以通过一个叫python-escpos的库来控制打印相关的功能接口。最后也是最重要的一个,便是用于将图片渲染成字符画的python-aalib,它把linux以C写成的aalib封装成python的库

However, I found out some serious problems: 1. the python-aalib running on RPi has bad performance, the rendering process takes nearly half a second, so I cannot get real time live show from the camera.(I didn't have time to investigate the reason); 2. The ASCII picture printed on the paper is too small to recognize things, while it takes too long to print a thumbnail pixel image.

然而,我在尝试过后发现一些比较严重的问题:1.在树莓派上跑python-aalib的时候性能很差,大概需要半秒才渲染出一张字符画,这样我就不能像实时的视频一样显示用户的动作了(由于没有太多时间深入调查,不知道是因为python的原因还是原来的C库就有这样的问题;2.在热敏打印纸上打印出来的照片太小了,无法识别出来图片是什么东西,如果直接打像素照片呢,速度又非常慢(这是由于热敏打印机对自定义图片打印的限制,它打的时候可以很快,但是之前需要很长时间把图片内容发到内存里)。

So I decided to switch to a PC solution with a web site hosting for holding the HTML ASCII image online. Extra work needs to be done. The picamera is not available on PC, so I search and found OpenCV's camera solution. It needs a conversion from OpenCV to PIL and the rest are the same.

于是我决定改用PC方案,配合一个网站来存放字符照片给用户查看。更多的工作需要完成。树莓派上的Picamra在PC上不适用,于是我又查找到了OpenCV的读取摄像头的方法,只需要把OpenCV捕捉下来的照片转成PIL形式的,剩下的就跟树莓派的一样了。

The web site needs an app that accepts uploads from the client. I just chose a simple and fast one "wheezy.web", which I never used before, and it's a chance to make a test. The original python-aalib only ports a subset of the features of the aalib. I'm not satisfied with only generating plain-text, but rather the more attractive grayscale html form. So I study the python-aalib source code and use ctypes to port more functions from aalib. Now the rendering and the uploading parts are ready, all I need is the python-qrcode that integrated with python-escpos to print a QR code for the link.

在网站上则需要开发一个小应用来接收来自客户端的上传。我选用了一个从来没用过,但是据说是非常快和易于使用的web框架"wheezy.web",正好用来测试一下。原来的python-aalib只封装了aalib功能的一个子集。我对它那只有普通文本的效果并不满足,实际上aalib包含了一个更漂亮的导出成带灰度的html的方法。于是我便研究了一下python-aalib的源代码并使用ctypes封装引自aalib的更多功能。现在渲染和上传的部分都已经准备好了,剩下的工作就只有使用集成了python-qrcode的python-escpos来打印包含网站链接的二维码而已。

qrcode-print-template

So the final demostration is a monitor, a usb camera, a laptop and a thermal printer that works on Maker Faire Shenzhen 2014.

于是最后的在2014深圳制汇节的展示方案是: 一个显示器,一个usb摄像头,一台笔记本和一台热敏打印机。


(Photo by bugeng)