[ocrfeeder] Try to maximize scan area



commit 9a2480f73ade36d58f623b539c656f1d728e9d3d
Author: scx <scx mail gmail com>
Date:   Tue Jan 14 20:27:52 2020 +0100

    Try to maximize scan area
    
    Some scanner by default select only a small area instead of full page.
    
    We want to fix it by trying to maximize the scan area, if possible.
    Not all devices are able to do this so we have to handle any exception.

 src/ocrfeeder/util/lib.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/src/ocrfeeder/util/lib.py b/src/ocrfeeder/util/lib.py
index f408743..ff9b314 100644
--- a/src/ocrfeeder/util/lib.py
+++ b/src/ocrfeeder/util/lib.py
@@ -157,6 +157,14 @@ def obtainScanners():
     except (RuntimeError, sane._sane.error) as msgerr:
         return None
 
+def getScannerOption (scandev, name):
+    options = scandev.get_options()
+
+    for option in options:
+        if option[1] == name:
+            return option
+    return None
+
 def scan(device):
     try:
         scandev = sane.open(device)
@@ -172,6 +180,13 @@ def scan(device):
             scandev.resolution = 300
         except:
             debug('Unable to set scanner resolution to 300 DPI. Using default.')
+        try:
+            scandev.tl_x = 0
+            scandev.tl_y = 0
+            scandev.br_x = getScannerOption(scandev, 'br-x')[8][1]
+            scandev.br_y = getScannerOption(scandev, 'br-y')[8][1]
+        except:
+            debug('Unable to set scan geometry. Using default.')
         result = scandev.scan()
         filename = tempfile.mktemp(suffix='.png')
         result.save(filename, 'PNG')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]