python-双面模式下的 twain 库从每一面获取单独的图像
python-twain library in duplex mode get separate image from each side
我正在尝试在双面模式下使用 python-twain 库进行扫描,并从每一侧获取两张图像。
import twain
sm = twain.SourceManager(0)
ss = sm.OpenSource('Plustek MobileOffice D600')
ss.SetCapability( twain.CAP_DUPLEXENABLED, twain.TWTY_BOOL, True )
ss.RequestAcquire(0,0)
rv = ss.XferImageNatively()
if rv:
(handle, count) = rv
twain.DIBToBMFile(handle, 'image.bmp')
该代码仅获取一张图像,但在 http://twainmodule.sourceforge.net/ , I don't see how to get take independently images from it. I know is possible because I could get in a demo from a close source library CLScan(http://www.commandlinescanning.com).
处提供了库文档
欢迎提出任何建议。
我在 GitHub 上找到了示例代码 TwainBackend.py。您可以使用循环来保存所有可用图像:
import twain
index = 0;
def next(ss):
try:
print ss.GetImageInfo()
return True
except:
return False
def capture(ss):
global index
rv = ss.XferImageNatively()
fileName = str(index) + '_image.bmp';
index+=1;
print rv;
if rv:
(handle, count) = rv
twain.DIBToBMFile(handle, fileName)
sm = twain.SourceManager(0)
ss = sm.OpenSource('Plustek MobileOffice D600')
try:
ss.SetCapability( twain.CAP_DUPLEXENABLED, twain.TWTY_BOOL, True)
except:
print "Could not set duplex to True"
print "acquire image"
ss.RequestAcquire(0,0)
while next(ss):
capture(ss)
print('Done')
我正在尝试在双面模式下使用 python-twain 库进行扫描,并从每一侧获取两张图像。
import twain
sm = twain.SourceManager(0)
ss = sm.OpenSource('Plustek MobileOffice D600')
ss.SetCapability( twain.CAP_DUPLEXENABLED, twain.TWTY_BOOL, True )
ss.RequestAcquire(0,0)
rv = ss.XferImageNatively()
if rv:
(handle, count) = rv
twain.DIBToBMFile(handle, 'image.bmp')
该代码仅获取一张图像,但在 http://twainmodule.sourceforge.net/ , I don't see how to get take independently images from it. I know is possible because I could get in a demo from a close source library CLScan(http://www.commandlinescanning.com).
处提供了库文档欢迎提出任何建议。
我在 GitHub 上找到了示例代码 TwainBackend.py。您可以使用循环来保存所有可用图像:
import twain
index = 0;
def next(ss):
try:
print ss.GetImageInfo()
return True
except:
return False
def capture(ss):
global index
rv = ss.XferImageNatively()
fileName = str(index) + '_image.bmp';
index+=1;
print rv;
if rv:
(handle, count) = rv
twain.DIBToBMFile(handle, fileName)
sm = twain.SourceManager(0)
ss = sm.OpenSource('Plustek MobileOffice D600')
try:
ss.SetCapability( twain.CAP_DUPLEXENABLED, twain.TWTY_BOOL, True)
except:
print "Could not set duplex to True"
print "acquire image"
ss.RequestAcquire(0,0)
while next(ss):
capture(ss)
print('Done')