Easy
scanning
A friend is an old man. He learned using a computer only a few years
ago. One of his goals was to scan pictures and send them by mail. He is
able to use a scanner software he doesn't like that. So I wrote a
little script for him. He just has to click on that script's icon. A
few
minutes later a new picture file appears in his files directory. That's
all. Then he can attach that picture file to a mail and send it. Below
is the script. It uses the SANE scan library and the ImageMagick
convert command:
#! /bin/bash
C=$(cat
.scan_counter)
C=$(( C + 1 ))
echo $C >
.scan_counter
[ ${#C} == 1 ]
&& C=0000$C
[ ${#C} == 2 ]
&& C=0000$C
[ ${#C} == 3 ]
&& C=0000$C
[ ${#C} == 4 ]
&& C=0000$C
cd ~
NAME="Scan_$C"
scanimage
--mode Color --resolution 300 -l 0 -t 0 -x 215 -y 297 --brightness 32
--contrast 10 > "$NAME.pnm"
convert
"$NAME.pnm" -scale 25% -rotate 180 -quality 85 "$NAME.jpg"
rm -f
"$NAME.pnm"
That command allways produces a 75 DPI picture. That suits my friends'
needs. Also the picture is the whole surface of the scanner. Most items
my friend scans are paper pages or books, so in most cases it is OK.
The problem is sometimes he scans a little item like a postcard. In
such cases the result is a bit odd. That's why I conceived a way for
him to get a cropped picture. He simply uses four little pieces of
thick cardboard. He can surround the object on the scanner's window
with thoses pieces of cardboard. Like this:
I wrote a C++ program that finds out the presence of the four dots on
each piece of cardboard. The program then infers the cut lines the
cardboards ask for. In next picture the four color lines are drawn by
the program and show its guess:
Then it crops the picture:
The source code of that C++ program is available here: http://www.4p8.com/eric.brasseur/scanner_vision.tar.gz
. I placed it under GNU Public License. It currently has the shape of a
quick hack.
The pictures above show the scene as seen from the scanner. When my
friend puts the pieces of cardboard around the object he actually
doesn't see the dots. On his side of the cardboards, he sees a black
dotted line on the side of the cardboard where the cut will occur:
It is not necessary to use all four pieces of cardboard. Just one can
be used, or two, or three... Each piece of cardboard simply shows where
the
user wants a cut line.
I could have implemented a simpler way to crop the picture. For example
a program that distinguishes the black background of the scanner,
detects where the scanned object is located and crops it out with a
margin. The images above show that in some cases parts of the scanned
object are difficult to distinguish from the scanner background. What's
more on my friend's scanner the background color and brightness change
a lot depending on the thickness of the object being scanned. Anyway I
could have written such a program. I prefered the little cardboards
system because it allows my friend to choose exactly where he wants the
image to be cropped. Besides he enjoys that system.
This is the scan script enhanced to make use of the C++ crop program:
#! /bin/bash
C=$(cat
.scan_counter)
C=$(( C + 1 ))
echo $C >
.scan_counter
[ ${#C} == 1 ]
&& C=0000$C
[ ${#C} == 2 ]
&& C=0000$C
[ ${#C} == 3 ]
&& C=0000$C
[ ${#C} == 4 ]
&& C=0000$C
cd ~
NAME="Scan_$C"
scanimage
--mode Color --resolution 300 -l 0 -t 0 -x 215 -y 297 --brightness 32
--contrast 10 > "$NAME.pnm"
convert
"tmp/$NAME.pnm" -scale 25% -rotate 180 "$NAME.bmp"
scanner_vision
"$NAME.bmp" "$NAME.cropped.bmp"
convert
"$NAME.cropped.bmp" -quality 85 "$NAME.jpg"
rm -f
"$NAME.pnm"
rm -f
"$NAME.bmp"
rm -f
"$NAME.cropped.bmp"
A further enhancement can be to create different kinds of cardboards.
Each type of cardboard piece has a different layout of dots, which
allows the C++ program to distinguish between them. For example one
cardboard can be used to show the orientation of the object. Another
set of cardboards can be used to ask for a different resolution. Say
you
want 300 DPI, well you put the "300 DPI" cardboard on the scanner
window. Yet another set of cardboards can be used to ask for a color
scan or black & white...
I thought of using such little white cardboards for photos taken with
a camera. For example that would allow a software to correct the color
temperature of the picture automatically. It just has to detect where
in the picture the cardboard is located and weight the color balance of
the white part of the cardboard. Several cardboards can be used to
correct the fish-eye effect of the camera.
Eric Brasseur
-
January 29 2005