abusenius / insaned

Simple daemon for polling button presses on SANE scanners
GNU General Public License v2.0
43 stars 13 forks source link

Batch mode? #4

Closed coaxial closed 7 years ago

coaxial commented 7 years ago

My scanner (Lide 210) has a button to scan a multi-page document: load the first page, press the button. When it's done, place the second page, press the button again, and so on until you run out of pages. At the end, each scan gets put back together in a multi-page PDF.

I'd like to reimplement this functionality using insaned. The twist is that I'm running it headless, so the only interface to the system is through the scanner buttons.

I was thinking of saving the individual scans in a separate directory from the one used when pressing the file button. Each page is scanned separately, and I'll write a daemon watching that directory. If no new file has been added there after a set timeout, it will collect all the files and assemble them in one multi-page PDF.

However, this isn't ideal because if I get interrupted scanning the pages it will create an incomplete PDF. I'm also handwaving the daemon part, but I'm not sure how to go about it just yet.

Did you ever think about this use case? Any idea how else that could be done?

coaxial commented 7 years ago

I've put a bit more thought into it, and I think the easiest solution would be to use the extra button to initiate a multi page scan, pressing the extra button for every page. Once every page has been scanned, pressing the scan button would concatenate all the pages into one file. It wastes the scan button but it's easier to implement because there is no need for a daemon or having to deal with the timeout triggering if the user gets interrupted while scanning the pages.

abusenius commented 7 years ago

I also have Lide 210, but I haven't thought about this feature (maybe because I've never seen how it works in windows).

I think, we should stick to the behavior, described in the user manual (which is similar to your suggestion), since this is what people are most probably used to:

SCAN START Button (left button with PDF label, reported as file button)

  • Saves the scanned image as a PDF file.

FINISH Button (second button with the |>| sign, reported as extra button)

  • Ends the operation and saves the scanned image in a PDF file.

So, my understanding is the following:

@Coaxial, what do you think about this?

abusenius commented 7 years ago

About implementation: creating PDFs from images is quite simple, convert from imagemagick can do this, I think it can be done with event scripts:

I can try this out on the weekend.

coaxial commented 7 years ago

You're right, I checked the manual online (https://www.manualowl.com/m/Canon/CanoScan-LiDE210/Manual/124735), and the buttons are used in the way you described: file scans the document. If it's a multipage document, file is pressed for every page scanned. After the user is done scanning the document (whether it's one page or several), they must press the extra button to signal this document is done; at which point every file in the scan directory is concatenated into one PDF.

You make a good point that I might want to copy a page while scanning a multipage document. Using the extra button to signal the end of the document would let me do that without aborting the current digitization process.

How do you use the autoscan button, aka scan? I believe with the original software, it figures out the best settings by itself (color hires if it's a photo, lineart lowres if text, etc.) Which settings do you have it mapped to?

Same question for the email button, do you use it to send the scan to a specific email? Or are you running the scanner on your desktop computer and thus have it open your mail client with the scan as an attachment?

Somewhat related: does the 600dpi resolution work on your system? When I try it, the image is distorted, similar to what is shown there: http://www.chiark.greenend.org.uk/~akanaber/lide110/graph-gray-600dpi.png (i.e. the grid should have squares, not rectangles). Oddly, 300 dpi is fine and not distorted.

abusenius commented 7 years ago

I use the default event scripts, just take a look what they do. In short, they just define different settings for different use cases, i.e. low resolution for email, high resolution for scan, grayscale for copy etc.

In my case, this is sufficient. I don't think that automatic detection would lead to better results, but if I would need to implement the autodetection of the "best" settings, I'd just scan with highest settings, then run some detection algorithm and convert/enhance the image according to the result.

My scanner is connected to a desktop PC, so scan shows the scanned image and email opens a new e-mail with attached image in thunderbird.

I have tried to scan a graph paper with 600 dpi and it looks correct, what version of SANE do you have and what settings have you used? Try this: scanimage --format tiff --mode Color --swdeskew=yes --swcrop=yes --resolution 600 > image.tiff I used version 1.0.25.

In any case, you can workaround the problem by scaling the result with imagemagick.

coaxial commented 7 years ago

I have the problem with --mode=lineart, if you scan a full size letter or A4 page in 600 dpi, you don't get the bottom of the page and the rest of it is stretched.

Did you find the swdeskew option makes any difference?

I have version 1.0.24

abusenius commented 7 years ago

Ok, with --mode lineart I also get such behavior (never tried that before). You might want to report this bug to SANE.

In my expirience, swdeskew works quite well for text documents, it corrects the image if the document got slightly rotated in scanner. With images and photos, the result might be somewhat unpredictable.

coaxial commented 7 years ago

I tried with 1.0.24 (latest in Debian's package manager), and 1.0.25git20150528 in Ubuntu. Both have the bug. I'm now trying to compile 1.0.25 from the latest git sources to see if I'll get more luck.

abusenius commented 7 years ago

Pierre, I have implemented batch mod using buttons file and extra, please test :) It should be sufficient to copy those scripts into /etc/insaned/events and adjust scan/PDF settings in them, if needed.

Required dependency: libtiff-tools

coaxial commented 7 years ago

Cool, I'll take a look now

coaxial commented 7 years ago

I added a few thoughts, eager to know yours. Also, do you know about shellcheck? I use it with TravisCI, it runs bash scripts through a static analysis engine to point out things like potentially dangerous expansions like rm $MYVAR/, unquoted variables etc. If you need, you can have a look at mine: https://github.com/Coaxial/insaned-config/blob/master/.travis.yml

It's pretty well integrated with GitHub and will run the tests for all your PRs and commits automatically.

abusenius commented 7 years ago

Haven't heard of shellcheck yet, but it sounds interesting, I'll check it out.