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 扫描的更多相关文章

  1. python twain模块

    >>> help(twain) Help on module twain: NAME twain - Created on Sep 4, 2011 DESCRIPTION @auth ...

  2. Python批量扫描服务器指定端口状态

    闲来无事用Python写了一个简陋的端口扫描脚本,其简单的逻辑如下: 1. python DetectHostPort.py iplist.txt(存放着需要扫描的IP地址列表的文本,每行一个地址) ...

  3. [Python] 文件扫描

    文件扫描 下载 https://github.com/YouXianMing/FileManager 细节 1. 基于Python 3.60,其他版本未测试 2. 支持扫描深度,不设置则扫描全部,设置 ...

  4. python 资产扫描01

    本地建立的三个文件: Asset1.txt 用来保存扫描到的资产 Asset2.txt 用来导入给定的资产 Repeat.txt 保存重复的资产 程序的功能: 1.资产扫描,以 位置:资产 格式保存到 ...

  5. python端口扫描

    简易版: #author:Blood_Zero #coding:utf-8 import socket import sys PortList=[21,22,23,25,80,135] # host= ...

  6. Python实现扫描作业配置自动化

    持续集成平台接入扫描作业是一项繁琐而又需要细致的工作,于是趁着闲暇时间,将代码扫描作业用Python代码实现了配置自动化. 每次配置作业的过程中,都会在checkcode1或者checkcode3上 ...

  7. python 端口扫描程序

    #! /usr/bin/env python3 #-*- coding:utf-8 -*- import socket import threading OPEN_COUNT = 0 lock = t ...

  8. python多线程扫描爆破网站服务器思路【笔记】

    这个扫描是概率问题,是需要字典的,以下代码是作为参考,字典可以去网上下载,我就不提供,我提供的是思路! #!/usr/bin/env python # coding=utf-8   from IPy ...

  9. Python脚本扫描给定网段的MAC地址表(scapy或 python-nmap)

    目录 用scapy模块写 用 python-nmap 模块写 python3.7  windows环境 以下两个都可以扫描指定主机或者指定网段的 IP 对应的 MAC 地址,然后保存到 csv 文件中 ...

随机推荐

  1. selenium-元素无法定位解决办法

    selenium-元素无法定位解决办法   有时会出现元素定位失败的情况,以百度首页为例,定位输入框,报错如下: selenium.common.exceptions.NoSuchElementExc ...

  2. TVM 优化 ARM GPU 上的移动深度学习

    TVM 优化 ARM GPU 上的移动深度学习 随着深度学习的巨大成功,将深度神经网络部署到移动设备的需求正在迅速增长.与桌面平台上所做的类似,在移动设备中使用 GPU 既有利于推理速度,也有利于能源 ...

  3. GPU核心技术开发

    GPU核心技术开发 由于上一节主要阐述GPU内部的工作流程和机制,为了简洁性,省略了很多知识点和过程,本节将对它们做进一步补充说明. 1.  CUDA技术 1)NVIDIA CUDA 是什么? NVI ...

  4. PointRCNN: 点云的3D目标生成与检测

    PointRCNN: 点云的3D目标生成与检测 PointRCNN: 3D Object Proposal Generation and Detection from Point Cloud 论文地址 ...

  5. MLPerf结果证实至强® 可有效助力深度学习训练

    MLPerf结果证实至强 可有效助力深度学习训练 核心与视觉计算事业部副总裁Wei Li通过博客回顾了英特尔这几年为提升深度学习性能所做的努力. 目前根据英特尔 至强 可扩展处理器的MLPerf结果显 ...

  6. 运用iGuard防御ADS权限维持

    权限维持是一门庞大的学问,当攻击者在入侵服务器获得主机权限后,往往会想尽办法隐藏其入侵途径以维持权限.权限维持的一般手段包括构造文件包含漏洞.构造远程任意代码执行漏洞.构造SQL注入点.利用系统自启动 ...

  7. 【Java面试真题】剑指Offer53.2——0~n-1中缺失的数字(异或、二分两种解法)

    [Java实现]剑指Offer53.2--0~n-1中缺失的数字:面试真题,两种思路分享 前面有另一道面试题[Java实现]剑指offer53.1--在排序数组中查找数字(LeetCode34:在排序 ...

  8. 【VBA】查找字符串

    老婆饼里有老婆吗 Sub test() aaa = "老婆饼里有老婆吗" If InStr(aaa, "老婆") <> 0 Then Debug.p ...

  9. SpringCloud(1)生态与简绍

    一:微服务架构简绍学习目标 1.技术架构的演变,怎么一步步到微服务的:2.什么是微服务,优点与缺点  :3.SOA(面向服务)与MicroServices(微服务)的区别 :4.Dubbo 与Spri ...

  10. daily plan

    想了想自己留的坑有点多了,写个计划提醒自己 一些没做出来的题 csp-s模拟测试54 z csp-s模拟测试b层加餐 string 平衡树+并查集 因为某杰的**安排,没时间改了csp-s模拟测试47 ...