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语言协程并发---互斥锁sync.Mutex
package main import ( "fmt" "sync" "time" ) /* mt.Lock() 抢锁 一次只能被一个协程锁 ...
- Jmeter——元件扩展,使其功能更全面
工具扩展 在之前的博文中,有介绍自定义函数.Java请求扩展,博文如下: Jmeter二次开发--基于Java请求 Jmeter二次开发--自定义函数 上述内容,是按自己的需要来进行针对性扩展,从而实 ...
- AIoT 2020 年分析
AIoT 2020 年分析 2020年,从智能手机到智能手表,从智能摄像头到智能汽车,随着AI.芯片.云计算.通信等基础技术的逐渐成熟,又一个行业来到了历史性的时刻--AIoT. 从"万物互 ...
- Velodyne VLP-16激光雷达数据分析
Velodyne VLP-16激光雷达数据分析 Velodyne VLP-16激光雷达保持了 Velodyne 在 LiDAR 中的突破性重要功能:实时收发数据.360 度全覆盖.3D 距离测量以及校 ...
- GPU上如何优化卷积
GPU上如何优化卷积 本文将演示如何在TVM中编写高性能卷积实现.我们以平方大小的输入张量和滤波器为例,假设卷积的输入是大批量的.在本例中,使用不同的布局来存储数据,以实现更好的数据局部性.缓冲区布局 ...
- 预测汽车级Linux专业技术的需求
预测汽车级Linux专业技术的需求 Anticipating need for Automotive Grade Linux expertise 在听了多年汽车级Linux(AGL)及其所有潜力之后, ...
- httprunner的简介、httprunner做接口测试入门知识,使用httprunner模拟get请求及post请求
一.httprunner的简介 HttpRunner 是一款面向 HTTP(S) 协议的通用测试框架,只需编写维护一份 YAML/JSON 脚本,即可实现自动化测试.性能测试.线上监控.持续集成等多种 ...
- spring如何集成第三方框架? 比如mybatis
实体Bean的创建: 1: 基于class构建, 2: 构造方法构建 3: 静态工厂方法创建 4: FactoryBean构建 spring如何集成第三方框架? 比如mybatis 在mybatis中 ...
- mysql 高级和 索引优化,目的:查的好,查的快,性能好
1-事物隔离级别: 更新丢失, 并发情况下,对同一字段进行更新,就会出现更新丢失,采用乐观锁,比较版本号或时间戳可解决 读未提交 解决了更新丢失但是会引起脏读, 二个session.sessionA中 ...
- spring赌上未来的一击:WebFlux性能实测
最近花了一点时间系统的测试验证了在SpringBoot框架下使用SpringMVC和Spring WebFlux两种框架开发接口,对比了响应时间以及压测吞吐量的区别. WebFlux&Spri ...