python twain 扫描
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 扫描的更多相关文章
- python twain模块
>>> help(twain) Help on module twain: NAME twain - Created on Sep 4, 2011 DESCRIPTION @auth ...
- Python批量扫描服务器指定端口状态
闲来无事用Python写了一个简陋的端口扫描脚本,其简单的逻辑如下: 1. python DetectHostPort.py iplist.txt(存放着需要扫描的IP地址列表的文本,每行一个地址) ...
- [Python] 文件扫描
文件扫描 下载 https://github.com/YouXianMing/FileManager 细节 1. 基于Python 3.60,其他版本未测试 2. 支持扫描深度,不设置则扫描全部,设置 ...
- python 资产扫描01
本地建立的三个文件: Asset1.txt 用来保存扫描到的资产 Asset2.txt 用来导入给定的资产 Repeat.txt 保存重复的资产 程序的功能: 1.资产扫描,以 位置:资产 格式保存到 ...
- python端口扫描
简易版: #author:Blood_Zero #coding:utf-8 import socket import sys PortList=[21,22,23,25,80,135] # host= ...
- Python实现扫描作业配置自动化
持续集成平台接入扫描作业是一项繁琐而又需要细致的工作,于是趁着闲暇时间,将代码扫描作业用Python代码实现了配置自动化. 每次配置作业的过程中,都会在checkcode1或者checkcode3上 ...
- python 端口扫描程序
#! /usr/bin/env python3 #-*- coding:utf-8 -*- import socket import threading OPEN_COUNT = 0 lock = t ...
- python多线程扫描爆破网站服务器思路【笔记】
这个扫描是概率问题,是需要字典的,以下代码是作为参考,字典可以去网上下载,我就不提供,我提供的是思路! #!/usr/bin/env python # coding=utf-8 from IPy ...
- Python脚本扫描给定网段的MAC地址表(scapy或 python-nmap)
目录 用scapy模块写 用 python-nmap 模块写 python3.7 windows环境 以下两个都可以扫描指定主机或者指定网段的 IP 对应的 MAC 地址,然后保存到 csv 文件中 ...
随机推荐
- GO学习-(32) Go实现日志收集系统1
Go实现日志收集系统1 项目背景 每个系统都有日志,当系统出现问题时,需要通过日志解决问题 当系统机器比较少时,登陆到服务器上查看即可满足 当系统机器规模巨大,登陆到机器上查看几乎不现实 当然即使是机 ...
- Sql server 多列去重复值,相同的只显示一条数据
CREATE TABLE #tp( headerNo VARCHAR(10), machineNO VARCHAR(10), descrption nVARCHAR(20), artNo VARCHA ...
- 大规模数据处理Apache Spark开发
大规模数据处理Apache Spark开发 Spark是用于大规模数据处理的统一分析引擎.它提供了Scala.Java.Python和R的高级api,以及一个支持用于数据分析的通用计算图的优化引擎.它 ...
- python+selenium基础篇,弹窗处理
1.弹窗如下图所示 2.处理方法 from selenium.webdriver.common.action_chains import ActionChains#导入鼠标操作包 from selen ...
- 操作系统-Linux命令
一.目录结构 #因为根目录与开机有关,开机过程中仅有根目录会被挂载, 因此根目录下与开机过程有关的目录(以下5个),不能与根目录放到不同的分区去. /etc:配置文件 /dev:所需要的装置文件 /l ...
- Unicode编码转换, MD5加密,URL16进制加密解密
一.站长网址:http://www.msxindl.com/ 1.Unicode与中文互转 16进制Unicode编码转换.还原 :http://www.msxindl.com/tools/uni ...
- org.junit.Assert(断言)
org.junit.Assert(断言) Assert是断言的意思,可以理解为"猜测",如果猜测错误,则抛出java.lang.AssertionError异常. 引入jar包 ...
- TKE 体验升级:更快上手 K8s 的24个小技巧
作者 王孝威,腾讯云容器产品经理,热衷于为客户提供高效的 Kubernetes 使用方式,为客户极致降本增效服务. 背景 "功能"解决是产品有或者没有一个能力的问题,有了" ...
- Go语言中的有缓冲channel和无缓冲channel区别
Go语言中的有缓冲channel和无缓冲channel区别 结论 ch1:=make(chan int)// 无缓冲 ch2:=make(chan int,1)// 有缓冲 无缓冲: 当向ch1中存值 ...
- centos7安装kubernetes1.18.5
一.设置hosts 修改主机名 [root@localhost kubernetes]# hostnamectl set-hostname master69 四台服务器安装kebernetes,一个m ...