在 pyinsane 上的设备选项中设置扫描坐标

Posted

技术标签:

【中文标题】在 pyinsane 上的设备选项中设置扫描坐标【英文标题】:Setting scan coordinates in device options on pyinsane 【发布时间】:2017-01-19 00:51:30 【问题描述】:

我使用 Sane 的命令行实用程序 (scanimage) 以便从我的扫描仪的透明单元扫描胶片。这是我一直在成功使用的命令:

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" \
> scan.tiff

我决定将其转移到 Python 代码中,使用 pyinsane 以便与我的图像处理工作流程进一步集成。这应该在 Python 代码中给出以下内容:

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]

但是我的第一次尝试没有成功,因为我不知道如何设置扫描坐标pyinsane。如您所见,我找到了合适的选项,但我不知道它们的单位是什么。scanimage 默认采用毫米为单位,但pyinsane 只采用整数。我尝试使用像素坐标无济于事。我想知道坐标参数采用什么单位,以及我是否以正确的顺序使用它们。

【问题讨论】:

【参考方案1】:

pyinsane 的选项描述实际上说这些值以毫米为单位:

Option: br-x
  Title: Bottom-right x
  Desc: Bottom-right x position of scan area.
  Type: <class 'pyinsane.rawapi.SaneValueType'> : Fixed (2)
  Unit: <class 'pyinsane.rawapi.SaneUnit'> : Mm (3)
  Size: 4
  Capabilities: <class 'pyinsane.rawapi.SaneCapabilities'> :[ Automatic, Soft_select, Soft_detect,]
  Constraint type: <class 'pyinsane.rawapi.SaneConstraintType'> : Range (1)
  Constraint: (0, 14160319, 0)
  Value: 20

但他们不是!我将br-x 变量的最大范围除以扫描仪扫描区域的宽度,得到数字 65536(即 2^16)。将坐标设置为毫米值乘以 65536 即可。也许这些值定义了步进电机的步数?

虽然 scanimage 将 -x-y 开关解释为宽度和长度,而 -l-t 开关解释为偏移量,但 pyinsane 采用右下角 x (br-x),顶部-左 y (tl-y) 等

【讨论】:

【参考方案2】:

Pyinsane 按原样报告 Sane 报告的内容。 Sane 会报告司机的报告。根据我的经验,所有驱动程序的行为方式并不完全相同,这可以解释这个奇怪的单元(换句话说,它可能是驱动程序的错误)。我以前从来没有真正担心过这个单位。有时间我会在扫描仪上查看它的内容。

无论如何,我不确定为什么它会说“mm”,因为根据我的经验,这里的单位实际上总是像素(同样,文档说它可以是“mm”,所以我需要检查)。 如果要扫描特定尺寸,则应查看分辨率(每英寸点数),然后通过数学计算得出您期望的尺寸(以像素为单位)。

【讨论】:

以上是关于在 pyinsane 上的设备选项中设置扫描坐标的主要内容,如果未能解决你的问题,请参考以下文章

在角度多选选项卡中设置文本

Windows 图像采集 - 在 C# 中设置设备属性

我可以在方法“findCurrentPlace()”中设置其他坐标吗?

Winform中设置ZedGraph鼠标悬浮显示线上的点的坐标并自定义显示的内容

Winform中设置ZedGraph鼠标悬浮显示线上的点的坐标并自定义显示的内容

无法在 Swift 4 上的 XCUITest 中设置设备方向