如何从Python和Django访问和控制文档扫描仪[ADF前端和后端],如柯达或Hp
我已经试过使用扫描仪了。它可以与柯达扫描仪进行通信,但它只扫描第一页,使其清晰,其余页面完全模糊。 而且pyinsane2不再具有可维护性。而且我也不知道如何使用Libsane,它是Pyinsane2的继承者。 我需要一个帮助来控制和扫描PythonDjango如何从Python和Django访问和控制文档扫描仪[ADF前端和后端],如柯达或Hp,django,python-3.6,Django,Python 3.6,我已经试过使用扫描仪了。它可以与柯达扫描仪进行通信,但它只扫描第一页,使其清晰,其余页面完全模糊。 而且pyinsane2不再具有可维护性。而且我也不知道如何使用Libsane,它是Pyinsane2的继承者。 我需要一个帮助来控制和扫描PythonDjango def scan_process(request): pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len
def scan_process(request):
pyinsane2.init()
try:
devices = pyinsane2.get_devices()
assert (len(devices) > 0)
device = devices[0]
print("I'm going to use the following scanner: %s" % (str(device)))
try:
pyinsane2.set_scanner_opt(device, "source", "ADF Front")
# pyinsane2.set_scanner_opt(device, 'duplex', ['both'])
except PyinsaneException:
print("No document feeder found")
pyinsane2.set_scanner_opt(device, 'mode', ['Color'])
pyinsane2.maximize_scan_area(device)
source = 'Auto'
if (device.options['source'].constraint_type
== pyinsane.SaneConstraintType.STRING_LIST):
if 'Auto' in device.options['source'].constraint:
source = 'Auto'
elif 'FlatBed' in device.options['source'].constraint:
source = 'FlatBed'
else:
print("Warning: Unknown constraint type on the source: %d"% device.options['source'].constraint_type)
res = 200
colour = 'Color'
# set_scanner_opt(device, 'resolution', res)
# set_scanner_opt(device, 'source', source)
# set_scanner_opt(device, 'mode', colour)
set_scanner_opt(device,'quality','maximum')
# set_scanner_opt(device,'duplex','both')
#
pyinsane2.maximize_scan_area(device)
scan_session = device.scan(multiple=True)
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]
file_name = 'Scan_'
file_extension = '.pdf' #.bmp
file_name_new = file_name + str(datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
lsfile_name = str((BASE_DIR + '/Bigflow_Demojs/media/' + file_name_new + file_extension))
lsfile_name_db = str(('/media/' + file_name_new + file_extension))
path = Path(lsfile_name)
path.parent.mkdir(parents=True, exist_ok=True)
image.save(lsfile_name) #### Save the Scanned Data
# from io import BytesIO ##### Detect The Barcode Data
# buffered = BytesIO()
# image.save(buffered, format="JPEG")
# img_str = base64.b64encode(buffered.getvalue())
# test = img_str
#
# obj_code = base64code.bar_qrcode()
# obj_code.base64_data = img_str
# ldict_data = obj_code.read_base64()
#
# barcode_data = ldict_data
# img_path_db = lsfile_name_db
#
# out_data = {}
# out_data = {"MESSAGE":"FOUND","DATA":ldict_data,"IMAGE_PATH":lsfile_name_db}
# image.save("GRT_%d.bmp" % idx)
# return JsonResponse(out_data,safe=False)
except Exception as e:
str(e)
# finally:
# pyinsane2.exit()
它需要扫描所有页面的正面和背面