Setting scan coordinates in device options on pyinsane
<p>I use Sane's command line utility (<code>scanimage</code>) in order to scan films from the transparency unit of my scanner. Here is the command that I have been using with success:</p>

<pre><code>scanimage --device-name pixma:04A9190D \
--source 'Transparency Unit' \
--resolution "4800" \
--format "tiff" \
--mode "color" \
-l "80.6" -x "56.2" -t "25.8" -y "219.2" \
&gt; scan.tiff
</code></pre>

<p>I have decided to move this to Python code, using <code>pyinsane</code> in order to enable further integration with my image-processing workflow. This should supposedly give the following in Python code:</p>

<pre><code>import pyinsane.abstract as pyinsane
device = pyinsane.get_devices()[0]

device.options['resolution'].value = 4800
device.options['mode'].value = 'Color'
device.options['source'].value = 'Transparency Unit'

# Setting coordinates to non-integers fails
device.options['tl-y'].value = 25.8
device.options['tl-x'].value = 80.6
device.options['br-y'].value = 219.2
device.options['br-x'].value = 56.2

scan_session = device.scan(multiple=False)
try:
    while True:
        scan_session.scan.read()
except EOFError:
    pass
image = scan_session.images[0]
</code></pre>

<p>But my first trials have been unsuccessful because I can not figure out how to set the scan coordinates <code>pyinsane</code>. As you see, I have found the appropriate options, but I don't know what unit they are in. <code>scanimage</code> takes the coordinates in millimetres by default, but <code>pyinsane</code> only takes integers. I have tried using pixel coordinates to no avail. I wonder what units the coordinate parameters take, and whether I am using them in the right order.</p>

<p>Pyinsane reports what Sane reports, as is. And Sane reports what the drivers report. In my experience, all the drivers don't behave exactly the same way, which may explain this weird unit (in other words, it could be a driver's bug). I never really worried about the unit before. I will check on my scanner what it says when I have some time..</p>

<p>Anyway I'm unsure why it does say 'mm', because in my experience, the unit here is actually always pixels (again, the documentation says it can be 'mm', so I need to check).
If you want to scan a specific size, you should have a look at the resolution (dot per inch), and then do the math to figure out the size in pixels you expect.</p>

python scanning sane pyinsane