Get image of only one sector in a scanner (python)

Asked

Viewed 373 times

3

Good afternoon! I need to develop a python application and I’m not getting the program to get an image of a scanner sector, only of the entire area that the scanner can scan (approximately a A4 sheet). I’m still a beginner in language.

My need is to monitor a scanner area, performing for example 2 images per minute. Only I don’t need all the A4 sheet that the scanner is capable of. I need a sector, a square 10cm x 10cm.

As soon as the software detects any change from the previous image to the current one, I would like it to play an alert sound and stop monitoring.

My problem is that using the lib Twain 1.0.5 and Image Scanner i cannot define an area. In all the tests I performed the obtained is always the "A4 sheet".

I am totally open to suggestions, including for programming language exchange. My fear (and guess) is that these aforementioned libraries do not realize what I need and I found no other test.

The closest I got to the necessary was when I modified the value in the "simple_base.py" file of the library Twain 1.0.5:

self.SD.Requestacquire(0, 0) # 1,1 to show scanner user interface

Adjusting the value from (0, 0) to (1, 1) the program opens a scanner driver window, where I can adjust so that the scanner only reads an area. The problem is that this is done manually. I wanted to leave an area as default because it is always the one that should be monitored.

Thank you very much!

  • How about cropping the image after scanning? Would it be acceptable for you? Cropping (Crop) is simple using Pillow.

  • @sergiopereira Unfortunately it is not appropriate because getting a high resolution image through a scanner, if it is the whole sheet, ends up taking more than 30 seconds and then the monitoring accuracy drops drastically. I had already thought about the possibility, but the test did not go very well... Thanks for the suggestion!

  • Let me get this straight: are you using a scanner to monitor change in any object (possibly a document)? I can’t believe Scanners are good for this kind of task. Mainly because he literally "scans" the image instead and captures it in one take, the performance for this type of task is really bad. Also, documents in a scanner don’t usually change on their own (they change when the user changes them). Wouldn’t it be better to use a webcam, for example? Maybe if you give more details of your problem it will be easier a suggestion.

1 answer

-2

Take the A4 sheet scanned by the program, see its pixel resolution (width, height), choose the area you want to use and write something like this using, replace the values with the lib functions you use (It’s just a hunch, I don’t know the lib you use, but there’s a good chance it’ll work):

if ImageChange in ResoluçãoAreaQueDesejaUtilizar:
    script

or try using the lib, Imagechange method arguments (Resolutionthat you want to use)

  • Thanks for the suggestion. I just don’t understand how you’re suggesting, since the resolution is the same for the whole sheet and it won’t be a part of it alone. The idea is not to cut the image after scanning, but to scan the desired part

  • Man, I’m sorry, I misread the lib you use... but can’t you insert an area into the scanning function? for example, 500x500 in pos 0, 0 ... also has this lib, looks good, serves? http://python-sane.readthedocs.org/en/latest/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.