Open kamidehlvi opened 3 years ago
I am using Ubuntu 18.4 LTS , Python 2.7
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?
iter = dev.multi_scan()
Hi , did u find any solution ?
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')
Hi, I am trying to do duplex scanning using Python-sane but unable to do duplex scanning please help me ... regards