0

我在 Python - Django 中使用 Pyinsane 2 通过网络 HP 打印机扫描图像。它可以正确检测设备。但是在给出 scan_session = device.scan(multiple=False) 时,它给出了 StopIteration 错误。

def scan_process(request): print('Scannned'); pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("我将使用以下扫描仪:%s" % (str(device )))

    try:
        pyinsane2.set_scanner_opt(device, 'source', ['ADF', 'Feeder'])

    except PyinsaneException:
        print("No document feeder found")

    pyinsane2.set_scanner_opt(device, 'mode', ['Gray'])

    pyinsane2.maximize_scan_area(device)
    scan_session = device.scan(multiple=False)
    try:
        while True:
            try:
                scan_session.scan.read()
            except EOFError:
                print("Got a page ! (current number of pages read: %d)" % (len(scan_session.images)))
    except StopIteration:
        print("Document feeder is now empty. Got %d pages" % len(scan_session.images))
    for idx in range(0, len(scan_session.images)):
        image = scan_session.images[idx]
        image.save("teste_%d.bmp" % idx)
finally:
    pyinsane2.exit()

def scan_process(request): print('Scannned'); pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("我将使用以下扫描仪:%s" % (str(device )))

    try:
        # pyinsane2.set_scanner_opt(device, 'source', ['ADF', 'Feeder'])
        pyinsane2.set_scanner_opt(device, 'source', ['ADF', 'Feeder'])

    except PyinsaneException:
        print("No document feeder found")
    # return

    # Beware: Some scanners have "Lineart" or "Gray" as default mode
    # better set the mode everytime
    pyinsane2.set_scanner_opt(device, 'mode', ['Gray'])

    # Beware: by default, some scanners only scan part of the area
    # they could scan.
    pyinsane2.maximize_scan_area(device)
    scan_session = device.scan(multiple=False)
    try:
        while True:
            try:
                scan_session.scan.read()
            except EOFError:
                print("Got a page ! (current number of pages read: %d)" % (len(scan_session.images)))
    except StopIteration:
        print("Document feeder is now empty. Got %d pages" % len(scan_session.images))
    for idx in range(0, len(scan_session.images)):
        image = scan_session.images[idx]
        image.save("teste_%d.bmp" % idx)
finally:
    pyinsane2.exit()
4

1 回答 1

0

立即停止迭代意味着扫描仪报告进纸器中根本没有纸张。如果您使用的是平板扫描仪..那么这是一个错误(但总是很难说这个错误是来自驱动程序还是 Pyinsane2 本身)。

请注意,我不再维护 Pyinsane2。我建议您尝试改用 Libinsane:https ://gitlab.gnome.org/World/OpenPaperwork/libinsane 。

于 2019-08-07T09:07:26.517 回答