Command line scanning

I needed to get scanned some pages of a catalog. I own a cheap Acer 3300U scanner that works nicely under Linux. It is not fast: It scans a 300dpi A4 color page in 50 seconds and it halves that when using gray instead. Lowering scan resolution to 150dpi reduces the scan to around 15 seconds.

But if you plan to scan more than one page you need to save each one and you have to provide a name for them. That means some mouse clicks and some typing at the keyboard. I was wondering if it was a better way, something like an automated script. I learned that there is a command line tool in the scan-tools package called scanimage that does just that: It allows you to launch a scan from a script. So what I did was to create a simple for loop and I used the loop variable to increase the page count. Each iteration was scanning a new page and converting it to a JPEG file with a sequential name.

After a power problem with the scanner I learned that next reconnection used a different device name, so I included that onto my script to avoid having to change it all the time. This is the final result:

if [ -z "$1" ]; then
echo "usage: scan.auto init_page end_page"
exit
fi
DEV=`scanimage -L|grep snapscan|cut -d " " -f 2|sed "s/\x60//"|sed "s/'//"`
echo "DEVICE=$DEV"
for((i=$1;i<=$2;i++)) ; do
scanimage -d $DEV -p --mode=gray --resolution=150> page.pnm
convert page.pnm p`printf "%03d" $i`.jpg
echo "Scanned page #" `printf "%03d" $i`
printf "press enter for next page\n"
read x
done

Comments

Popular posts from this blog

VFD control with Arduino using RS485 link

How to get sinusoidal s-curve for a stepper motor

Importing OpenSCAD designs into Onshape