因此,我目前正在使用python解密从OCR程序检索到的单词。
我正在使用的当前代码解读单词是:
import numpy as nm
import pytesseract
import cv2
import ctypes
from PIL import ImageGrab
def imToString():
# Path of tesseract executable
pytesseract.pytesseract.tesseract_cmd =r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
while(True):
# ImageGrab-To capture the screen image in a loop.
# Bbox used to capture a specific area.
cap = ImageGrab.grab(bbox =(687, 224, 1104, 240))
# Converted the image to monochrome for it to be easily
# read by the OCR and obtained the output String.
tesstr = pytesseract.image_to_string(
cv2.cvtColor(nm.array(cap), cv2.COLOR_BGR2GRAY),
lang ='eng')
checkWord(tesstr)
def checkWord(tesstr):
dictionary =['orange', 'marshmellow']
scrambled = tesstr
for word in dictionary:
if sorted(word) == sorted(scrambled):
print(word)
imToString()
我想知道是否还有[[减少所需的时间:
import numpy as nm
import pytesseract
import cv2
import ctypes
from PIL import ImageGrab
def imToString(dictionary):
# Path of tesseract executable
pytesseract.pytesseract.tesseract_cmd =r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
while(True):
# ImageGrab-To capture the screen image in a loop.
# Bbox used to capture a specific area.
cap = ImageGrab.grab(bbox =(687, 224, 1104, 240))
# Converted the image to monochrome for it to be easily
# read by the OCR and obtained the output String.
tesstr = pytesseract.image_to_string(
cv2.cvtColor(nm.array(cap), cv2.COLOR_BGR2GRAY),
lang ='eng')
checkWord(tesstr, dictionary)
def checkWord(tesstr, dictionary):
scrambled = tesstr
for word in dictionary:
if sorted(word) == sorted(scrambled):
print(word)
# ... Create your dictionary somewhere else and pass it in:
dictionary =[sorted('orange'), sorted('marshmellow')]
imToString(dictionary)