Skip to content
This repository has been archived by the owner on Dec 30, 2018. It is now read-only.

Getting a very long image in windows #36

Open
yuyudhan opened this issue Dec 14, 2017 · 7 comments
Open

Getting a very long image in windows #36

yuyudhan opened this issue Dec 14, 2017 · 7 comments

Comments

@yuyudhan
Copy link

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 jflesch added the bug label Dec 14, 2017
@jflesch
Copy link
Member

jflesch commented Dec 14, 2017

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

@yuyudhan
Copy link
Author

@jflesch
Copy link
Member

jflesch commented Dec 14, 2017

  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
Copy link
Author

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
Copy link
Member

jflesch commented Dec 14, 2017

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
Copy link
Author

Thanks it worked, :)

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

@jflesch
Copy link
Member

jflesch commented Dec 14, 2017

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

@jflesch jflesch reopened this Dec 14, 2017
@jflesch jflesch added the WIA label Jan 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants