微学网

热门关键词:   as  thinkphp  ecshop  xxx  商务通  www.ymwears.cn
热门: ASP.NET PHP编程 ASP编程 JSP编程 Python

python twain 扫描

发布时间:2021-05-14 来源:未知 点击:
def multiScan(self):
    """ Scan and return an array of PIL objects 
        If no images, will return an empty array
    """

    self.scanner.RequestAcquire(0, 1)
    images = []
    handles = []
    try:
        handle, more = self.scanner.XferImageNatively()
        handles.append(handle)
    except twain.excDSTransferCancelled:
        return []
    while more != 0:
        try:
            handle, more = self.scanner.XferImageNatively()
            handles.append(handle)
        except twain.excDSTransferCancelled:
            more = 0

    for handle in handles:
        images.append(Image.open(StringIO(twain.DIBToBMFile(handle))))
        twain.GlobalHandleFree(handle)

    return images

 

import twain

sm = twain.SourceManager(0)
ss = sm.OpenSource()

for i in range(3):  //for ex. 3 documents in the scanner device
   ss.RequestAcquire(0,0)
   rv = ss.XferImageNatively()
   if rv:
       (handle, count) = rv
       twain.DIBToBMFile(handle, '{i}.bmp'.format(i))

 

import twain

sm = twain.SourceManager(0)
sm.SetCallback(onTwainEvent)
ss = sm.OpenSource()
index = 0

for i in range(3):  //for ex. 3 documents in the scanner device
   ss.RequestAcquire(0,0)

def onTwainEvent(event):
    if event == twain.MSG_XFERREADY:
        saveImage()

def saveImage():
    rv = ss.XferImageNatively()
    if rv:
        (handle, count) = rv
        twain.DIBToBMFile(handle, '{index}.bmp'.format(index))
        index += 1

 

import twain 
sm = twain.SourceManager(0) 
ss = sm.OpenSource() 
ss.RequestAcquire(0,0) 
rv = ss.XferImageNatively() 
if rv: 
(handle, count) = rv 
twain.DIBToBMFile(handle, 'image.bmp')

 1、降低扫描分辨率、能用灰度就不用彩色、能用24位彩色就不用32位彩色

2、使用自动进纸器
3、采用高压缩比的图像格式,能用jpg就不用tiff,能用tiff就不用bmp
Source.GetCapabilityDefault(CapabilityCode)
Source.GetCapability(CapabilityCode)
Source.GetCapabilityCurrent(CapabilityCode)
Source.SetCapability(CapabilityCode)
Source.ResetCapability(CapabilityCode)
Source.GetImageInfo():返回XResolution, YResolution, ImageWidth, ImageLength, SamplesPerPixel, BitsPerSample, BitsPerPixel, Planar, PixelType, Compression
Source.GetImageLayout():返回((left, top, right, bottom) document_number, page_number, frame_number)

One of the CAP_* (Generic Capabilities), ICAP_ (Image Capabilities)


这就是微学网-程序员之家为你提供的"python twain 扫描"希望对你有所帮助.本文来自网络,转载请注明出处:http://www.weixuecn.cn/article/14474.html
网络编程 | 前端制作 | 数据库 | CMS教程 | 脚本编程 | 框架 | 服务器 | 微信开发 | APP开发 | 学习教程 |

凡本网站转载的文章、图片等资料的版权归版权所有人所有,因无法和版权所有者一一联系,如果本网站选取的文/图威胁到您的权益,请您及时和本网站联系。 我们会在第一时间内采取措施,避免给双方造 成不必要的损失。
© 2015-2021 微学网 版权所有,并保留所有权利。 备案号:粤ICP备09051474号-1

菜鸟学习网,提供各类程序编程入门,技巧,手机游戏下载站