Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to do Duplex Scanning #70

Open
kamidehlvi opened this issue Aug 17, 2021 · 4 comments
Open

Unable to do Duplex Scanning #70

kamidehlvi opened this issue Aug 17, 2021 · 4 comments

Comments

@kamidehlvi
Copy link

kamidehlvi commented Aug 17, 2021

Hi, I am trying to do duplex scanning using Python-sane but unable to do duplex scanning please help me ... regards

import scanPython
from PIL import  Image

mode = 'grey'

var = scanPython.init()
print("sane version ", var)
devices = scanPython.get_devices()
print('Available devices:', devices)

dev = scanPython.open(devices[0][0])
dev.__setattr__(2,'ADF Duplex') 
print("Current Source",dev.__getattr__(2))
dev.set_mode =mode
dev.resolution = 200
dev.start()
iterator = dev.multi_scan()
progress = True

while progress:
    try:
        image = iterator.next()
 except:
        progress = False
        break
#dev.cancel()

dev.close()
@kamidehlvi
Copy link
Author

I am using Ubuntu 18.4 LTS , Python 2.7

@kamidehlvi
Copy link
Author

iter = sane._SaneIterator(dev)
iter = dev.multi_scan()

Its working now as iterator class was not used ... Another question is how can we save the images during Next() within while loop are add them in an array but how can we identify Front and Back side of the scanned images please?

@aravindor
Copy link

iter = dev.multi_scan()

Hi , did u find any solution ?

@furqanazhar
Copy link

furqanazhar commented Feb 15, 2024

i am unable to perform duplex scanning with below code, kindly help me here. Below is my code.

import os
from PIL import Image
import sane

# Initialize sane
ver = sane.init()
print('SANE version:', ver)

# Get devices
devices = sane.get_devices()
print('Available devices:', devices)

# Open first device
dev = sane.open(devices[0][0])
try:
    dev.br_x = 320.
    dev.br_y = 240.
except:
    print('Cannot set scan area, using default')

params = dev.get_parameters()
print('Device parameters:', params)

# Create a directory to store scanned images
output_dir = "scanned_images"
os.makedirs(output_dir, exist_ok=True)

# Start scanning
images_list = []
try:
    # Perform scanning operation
    images = dev.multi_scan()
    print('Scanning documents')

    # Save each scanned image to a separate file
    for i, image in enumerate(images):
        output_filename = os.path.join(output_dir, f"page_{i + 1}.png")
        # Convert the image to PIL Image object
        pil_image = Image.frombytes('RGB', image.size, image.tobytes())
        # Rotate the image
        pil_image = pil_image.rotate(180)
        # Save the image
        pil_image.save(output_filename)
        images_list.append(output_filename)
        print(f"Saved {output_filename}")

except KeyboardInterrupt:
    pass

print('Converting images to pdf')

images = []
for image in images_list:
    i = Image.open(image)
    images.append(i)

images[0].save(f'{output_dir}/scan.pdf', "PDF", resolution=300.0, save_all=True, append_images=images[1:])
print('Conversion complete')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants