0

I am trying to scan using python-twain library in duplex mode and get two images one from each side.

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') 

The code only get one image but with the library documentation provided at 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).

Any suggestions will be welcome.

mcanet
  • 59
  • 8
  • 1
    Is it possible that the one image is overridden by the other? – Rachel Mar 30 '15 at 10:00
  • I think it is not overridden. And variable 'count' is not increasing to 2 stay in 1. The problem documentation of library is very poor. – mcanet Mar 30 '15 at 19:59
  • 1
    Yes, that's a trade-off of open source products. I recommend you check the following things: 1. Verify if the duplex mode is set successfully 2. You may need to set cap_xfercount. check [this post](http://stackoverflow.com/questions/1260357/twain-question-is-it-possible-to-scan-just-one-document-from-feeder) and see if it helps. – Rachel Mar 31 '15 at 08:05
  • @Rachel: when i used the answer code, then the duplex mode is failing to set True. Please advise. we have to make this answer reliable. i have few TWAIN devices. all the other answers are confusing. –  Apr 05 '16 at 06:52

1 Answers1

0

I found the sample code TwainBackend.py on GitHub. You can use a loop to save all available images:

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')
mcanet
  • 59
  • 8
yushulx
  • 11,695
  • 8
  • 37
  • 64
  • NOT -working to print front and rear. nor even working to save more pages. Please can you update how to duplex scan rear and front please? –  Apr 05 '16 at 06:33
  • I tried `ss.set_capability(twain.CAP_DUPLEXENABLED, twain.TWTY_BOOL, True)` but still duplex not happening fails. –  Apr 05 '16 at 06:47