openpaperwork / pyinsane

Python library to access and use image scanners (Linux/Windows/etc) (Sane/WIA) -- Moved to Gnome's Gitlab
https://gitlab.gnome.org/World/OpenPaperwork/pyinsane
63 stars 24 forks source link

Getting a very long image in windows #36

Open yuyudhan opened 6 years ago

yuyudhan commented 6 years ago

While in linux system it the scan_adf.py and scan.py are working fine, but in windows systems the scripts are generating very long images. Please see attachment. Height of scanned image is 9000 px.

1

Is there a setting which can be set to correct this issue?

jflesch commented 6 years ago

Can you paste the output of list_all.py in a pastebin and post the link here please ?

yuyudhan commented 6 years ago

Here: @jflesch

https://pastebin.com/0LSf5NET

jflesch commented 6 years ago
  Option: yextent
    Title:
    Desc:
    Type: None
    Unit: None
    Size: 4
    Capabilities: Access: rw                                                                                                Constraint type: None
    Constraint: (32, 36600)
    Value: 36600

Hm, 36600 is far too much. I think your driver is returning a crappy maximum size ...

As a workaround, just before you scan, you can try to add something like:

pyinsane2.set_scanner_opt(device, 'yextent', [2550 * 2])  # 2 times the max xextend

If it does work, I guess I will have to add yet-another-workaround in pyinsane2.maximize_scan_area.

yuyudhan commented 6 years ago

Still getting the same issue, getting following dimensions.

image

Following is my overall script scan_adf.py

#!/usr/bin/env python3

import os
import sys

import pyinsane2

def main(args):
    dstdir = args[0]

    devices = pyinsane2.get_devices()
    assert(len(devices) > 0)
    device = devices[0]

    print("Will use the scanner [%s](%s)"
          % (str(device), device.name))

    pyinsane2.set_scanner_opt(device, "source", ["ADF", "Feeder"])
    # Beware: Some scanner have "Lineart" or "Gray" as default mode
    pyinsane2.set_scanner_opt(device, "mode", ["Color"])
    pyinsane2.set_scanner_opt(device, "resolution", [75])

    pyinsane2.set_scanner_opt(device, 'yextent', [2550 * 2])  # 2 times the max xextend

    pyinsane2.maximize_scan_area(device)

    # Note: If there is no page in the feeder, the behavior of device.scan()
    # is not guaranteed : It may raise StopIteration() immediately
    # or it may raise it when scan.read() is called

    try:
        scan_session = device.scan(multiple=True)
        print("Scanning ...")
        while True:
            try:
                scan_session.scan.read()
            except EOFError:
                print("Got page %d" % (len(scan_session.images)))
                img = scan_session.images[-1]
                imgpath = os.path.join(dstdir, "%d.jpg" %
                                       (len(scan_session.images)))
                img.save(imgpath)
    except StopIteration:
        print("Got %d pages" % len(scan_session.images))

if __name__ == "__main__":
    args = sys.argv[1:]
    if len(args) <= 0 or args[0][0] == '-':
        print("Usage:")
        print("  %s <dst directory>" % sys.argv[0])
        sys.exit(1)
    pyinsane2.init()
    try:
        main(args)
    finally:
        pyinsane2.exit()
jflesch commented 6 years ago

pyinsane2.set_scanner_opt(device, 'yextent', [2550 * 2]) # 2 times the max xextend ^ Please put this line after maximize_scan_area. Otherwise maximize_scan_area will override it.

yuyudhan commented 6 years ago

Thanks it worked, :)

Setting the yextent based on the A4 inch size proportions at 1800 for 150 DPI images.

jflesch commented 6 years ago

I'm reopening this ticket. I'll add a workaround in maximize_scan_area : When the values are obviously insane (crazy ratio) --> take a guess :p