Printing long PDF documents is sometimes tedious, especially if you have a dull network printer. You might know the case that for mysterious reasons the printer just does nothing for a very long time and thereafter it seems to have forgotten about the actual print job.
Sometimes printing can still be accomplished by sending only a few pages of the PDF document in distinct print jobs. Doing this manually is also tedious, so here is a simple Python script that breaks up a PDF document into many PDFs with just 2 pages (using pdftk) and spools them via lpr (the package cups-pdf is required for this).
This blog is supposed to be a collection of random, unrelated, little ideas, thoughts, and discoveries, which I assume to be helpful to a negligible part of the world's population and wish to share out of pure altruism. If posts appear really weird, maybe you have the wrong kind of humor. Many of the posts are science/technology related. If you are opposed to that, stop reading here! Comments, criticism, corrections, amendments, questions are always welcome.
2013-03-02
Print PDFs by Creating Multiple Print Jobs
2013-02-07
Detect Printer Steganography
![]() |
| click on the image to enlarge |
I was curious if it was possible to visualize the pattern. In the article mentioned above, a test setup with a microscope and blue LED is described. Alternatively I found that it was sufficient to use a simple scanner and do some post processing with GIMP. Many scanners allow to scan with equal or higher resolutions and color depths than the printer can print.
The test page was printed with 600 dpi and also scanned with this resolution. The color depth was set to 16 bit. To make the little dots visible, an edge detection filter (in Gimp 2.6 under Filters, Edge-Detect, Edge...) was used. In the resulting image, the dots were visible best in the blue channel. The other two channels were removed as described here by adding an entirely green and an entirely red layer and setting the blending mode to subtract.
An excerpt of the empty part of the page can be seen here:
![]() |
| click on the image to enlarge |
2013-01-27
Typesetting Word-By-Word Translations
Recently I was asked how to typeset documents with a word-by-word translation like the following:
As I have learned, linguists have the fancy word Interlinear Gloss for this. There are several Latex packages available for this purpose. Among them is gb4e which I decided to use.
For simplicity it is assumed that the text to be 'glossed' is provided as a plain text file with sentences delimited by '. ', '? ' or '! ' (2 spaces) and words separated by individual spaces. The implementation of a small script that creates a document with nicely aligned words is very straight forward. The dictionary needs to be provided as a .csv file.
Unfortunately the task can not be fully automated. Breaking text into sentences requires some knowledge about a specific language. So does breaking sentences into words. Ideally the dictionary should also have some capability to detect flections, etc. The script just generates a Latex file that can be modified manually.
The script can be downloaded here.
| Welche | Farbe | hat | der | gelbe | Bus? |
|---|---|---|---|---|---|
| Which | color | has | the | yellow | bus? |
As I have learned, linguists have the fancy word Interlinear Gloss for this. There are several Latex packages available for this purpose. Among them is gb4e which I decided to use.
For simplicity it is assumed that the text to be 'glossed' is provided as a plain text file with sentences delimited by '. ', '? ' or '! ' (2 spaces) and words separated by individual spaces. The implementation of a small script that creates a document with nicely aligned words is very straight forward. The dictionary needs to be provided as a .csv file.
Unfortunately the task can not be fully automated. Breaking text into sentences requires some knowledge about a specific language. So does breaking sentences into words. Ideally the dictionary should also have some capability to detect flections, etc. The script just generates a Latex file that can be modified manually.
The script can be downloaded here.
Labels:
interlinear gloss,
latex,
Python,
word-by-word translation
2012-12-30
Aquarium Surveillance
Surveilling fish in an aquarium with a simple webcam is a fun activity for young and old. The following post describes a simple software setup that was used to continuously upload live still images of a small aquarium.
Nothing more is required than an aquarium, a webcam and a Linux computer with Internet connection. Optionally the aquarium may be substituted by a hamster cage. ;)
Probably ffmpeg could be used as an alternative to stream live video. However it was found that ffmpeg crashes rather often and that the encoding of popular video formats is CPU intense, which is especially infeasible on older computers. Another alternative for live video would be to use mjpegstreamer, which is especially resource preserving. Unfortunately the project seems to be inactive now and no 64-bit binaries are provided.
Therefore it was concluded that the best compromise would be to stream still images at the maximum resolution of the webcam and a refresh rate of a couple seconds. Many programs are suitable to acquire images. In this case fswebcam was chosen, because it is small and simple and can be found in the Debian/Ubuntu repositories.
Watching the fish should also have a social component. Therefore an Xajax sample program was used to provide a simple comment function ("graffiti wall"). The sample program can be tested and downloaded here.
The following packages need to be conveniently installed from the software repositories if not already present:
sudo apt-get install apache2 php5 fswebcam
Normally the images acquired with fswebcam would be written to disk continuously. To avoid letting the hard disk suffer too much, a ramdisk is created. This can easily be done by adding the following line to /etc/fstab:
#ramdisk for aquarium photos
ramfs /var/www/aquarium/aqua_ramdisk ramfs defaults 0 0
You can download the script and the modified xajax web program here.
The webcam.sh script needs to registered for automatic startup. A description how to do this can be found here. The web program can simply be copied to the apache web folder eg. /var/www/aquarium.
2012-12-27
"Distributed" Video Mass Converting
Assume the following situation that occurred to me recently:
There is a slow computer A with lots of disk space (eg. an old computer that is used as a NAS) and a faster computer B with only little disk space. A holds gigabytes of video clips in many different files that you want to do some CPU intense processing on, eg. re-encoding to another video format.
So what you probably want to do for every video clip is the following:
1. download video clip from A to B
2. process video clip on B
3. upload converted clip from B to A
4. delete original (and converted) clip on B
It is assumed that B can ssh/scp into A and that public key authentication is used. Otherwise it would be necessary to enter the password for every individual file. Moreover it is assumed that A and B are connected by a sufficiently fast network.
A simple script (runs on B) that was used to perform the steps 1-4 can be found here. An additional example script is provided that uses ffmpeg to scale video clips down to 720p.
There is a slow computer A with lots of disk space (eg. an old computer that is used as a NAS) and a faster computer B with only little disk space. A holds gigabytes of video clips in many different files that you want to do some CPU intense processing on, eg. re-encoding to another video format.
So what you probably want to do for every video clip is the following:
1. download video clip from A to B
2. process video clip on B
3. upload converted clip from B to A
4. delete original (and converted) clip on B
It is assumed that B can ssh/scp into A and that public key authentication is used. Otherwise it would be necessary to enter the password for every individual file. Moreover it is assumed that A and B are connected by a sufficiently fast network.
A simple script (runs on B) that was used to perform the steps 1-4 can be found here. An additional example script is provided that uses ffmpeg to scale video clips down to 720p.
2012-10-24
OpenCV Background Subtraction in Python
Recently, I tried finding an example of Background Subtraction being done in OpenCV and Python without success. The code is not complicated or special in any way. However, I guess, the example might be helpful, if you want to get started with Background Subtraction quickly.
The script reads a video file and writes out a mask for every frame.
Unfortunately there seem to be no Python bindings for BackgroundSubtractorMOG2 at the time of this writing.
The script reads a video file and writes out a mask for every frame.
#!/usr/bin/env python #-*- encoding: utf-8 -*- import cv2 import numpy bgs = cv2.BackgroundSubtractorMOG(24*60, 1, 0.9, 0.01) capture = cv2.VideoCapture("00185.MTS.mp4") cv2.namedWindow("input") a = 0 while(True): f, img = capture.read() fgmask = bgs.apply(img) #cv2.imshow("input", fgmask) #cv2.waitKey(1) cv2.imwrite("./pngs/image-"+str(a).zfill(5)+".png", fgmask) a = a + 1 print(a)
Unfortunately there seem to be no Python bindings for BackgroundSubtractorMOG2 at the time of this writing.
2012-10-06
Buggy projectM Music Visualizations
Today I tried visualizing some music using projectM and qmmp. Using a qmmp plugin provided in the Ubuntu repositories, music visualization was especially easy to set up and use.
Unfortunately I found that some of the visualizations are quite buggy and can easily end your music listening experience with a nasty crash of the music player.
The faulty visualizations are part of the Ubuntu package projectm-data (version 2.0.1+dfsg-12).
Here is a script that removes all visualizations that are faulty in my opinion. I do not claim this list to be exhaustive, but in my case it ended disturbing crashes.
Unfortunately I found that some of the visualizations are quite buggy and can easily end your music listening experience with a nasty crash of the music player.
The faulty visualizations are part of the Ubuntu package projectm-data (version 2.0.1+dfsg-12).
Here is a script that removes all visualizations that are faulty in my opinion. I do not claim this list to be exhaustive, but in my case it ended disturbing crashes.
Subscribe to:
Posts (Atom)


