tesseract和多线程
Tesseract
Tesseract简介
- 介绍 —— 将图像翻译成文字的OCR软件,目前由谷歌赞助,公认最优秀、最准确的开源OCR库,具有高识别度和高灵活性。
- 调用方法:
import pytesseract
from PIL import Image —— PIL是python的图像处理库
pytesseract.pytesseract.tesseract_cmd = r’tesseract软件路径’ —— 指定tesseract的软件
tessdata_dir_config = r’–tessdata-dir “tessdata路径”’ —— 指定tessdata的路径
image = Image.open(‘文件路径及文件名和后缀’) —— 打开图片
result = pytesseract.image_to_string(image, lang=‘eng’, config=tessdata_dir_config) —— 获取图片的内容
多线程
- 简介 —— 一个程序内线程是最小的执行单位,每个程序最少有一个线程(称为主线程),多线程就是在一个程序内多个线程同时执行(多个子线程)
多线程创建
-
创建方法:
- 通过函数创建 —— 使用threading模块中的Thread类,Thread类中有个target参数需要传递一个函数对象(函数对象是多线程逻辑)
- 通过类创建 —— 类需要继承threading.Thread父类,并重写run()方法,在run()方法中实现多线程逻辑
-
调用方法:
-
函数创建:
import threading
变量 = threading.Thread(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)- target:可调用对象(函数或方法)
- name:线程名称,默认为“Thread-N”形式的名称
- args:传入给target参数中可调用对象的参数,默认为空元组
- kwargs:传入给target参数中可调用对象的关键字参数,默认为空字典
-
类创建:
import threading
class A(threading.Tread):
def run():
代码块
-
通过函数创建多线程
- 方法:
变量 = threading.Thread(target=函数对象) —— 创建线程
变量.start() —— 线程开始执行
import threading
import time
def studying():
for i in range(3):
print('正在学习')
time.sleep(1)
def eating():
for i in range(3):
print('正在吃饭')
time.sleep(1)
def run