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 文件中 ...
随机推荐
- CVPR2019论文解读:单眼提升2D检测到6D姿势和度量形状
CVPR2019论文解读:单眼提升2D检测到6D姿势和度量形状 ROI-10D: Monocular Lifting of 2D Detection to 6D Pose and Metric Sha ...
- Dockerfile构建实践
Dockerfile构建实践 本文介绍了用于构建有效图像的推荐最佳实践和方法. Docker通过从一个Dockerfile文本文件中读取指令来自动构建映像,该文本文件按顺序包含构建给定映像所需的所有命 ...
- VTA硬件
VTA硬件 提供了VTA硬件设计的自上而下的概述.本硬件设计涵盖两个级别的VTA硬件: VTA设计及其ISA硬件-软件接口的体系结构概述. VTA硬件模块的微体系结构概述以及计算核心的微代码规范. V ...
- MinkowskiEngine基准测试
MinkowskiEngine基准测试 介绍卷积层和小型U网络的前馈和后馈通过时间.可以将具有相同张量步幅,步幅和内核偏移的内核映射重新用于其他层,可以在大型nueral网络中使用的所有层上,分摊此页 ...
- 视频系列:RTX实时射线追踪(上)
视频系列:RTX实时射线追踪(上) Video Series: Practical Real-Time Ray Tracing With RTX RTX在游戏和应用程序中引入了一个令人兴奋的和根本性的 ...
- 尚硅谷Java——宋红康笔记【day11-day18】
day11 Eclipse中的快捷键: * 1.补全代码的声明:alt + / * 2.快速修复: ctrl + 1 * 3.批量导包:ctrl + shift + o * 4.使用单行注释:ctrl ...
- 菜鸟刷题路:剑指 Offer 06. 从尾到头打印链表
剑指 Offer 06. 从尾到头打印链表 class Solution { public int[] reversePrint(ListNode head) { Stack<Integer&g ...
- Druid数据库连接池基本使用
一.导入Druid的jar包和数据库驱动jar包 二.定义配置文件 与c3p0不同,Druid的配置文件是properties形式的.而且Druid不像c3p0那样可以自动加载配置文件,Druid需要 ...
- python operator操作符函数
本模块主要包括一些Python内部操作符对应的函数.这些函数主要分为几类:对象比较.逻辑比较.算术运算和序列操作.
- 使用sign签名发送请求
import CryptoJS from "crypto-js"; import urlencode from "urlencode"; methods:{ a ...