fishyboteso/fishy/engine/fullautofisher/tesseract.py
Adam Saudagar a964c65776 full auto bug fixing
- changed engine.toggle_start to abstract method
- check for state before turning off bot engine
- added and corrected logging messages for contorls and calibration
- callibrate._get_factor returning None fixed
- optimized controls
- removed config for show crop
- recorder now runs asksaveasfile in gui thread and blocks itself till resoponse
- corrrected logic for saving failed files
- semifisher dont log started bot engine if not ran from gui
- added file name label in full auto config top
- call in thread now can return values
- gui now saves location when closed
- dynamic config location, now uses correct document folder if config file is not found in incorrect document folder
2020-12-01 02:34:33 +05:30

51 lines
1.5 KiB
Python

import logging
import os
import tempfile
import uuid
from datetime import datetime
from zipfile import ZipFile
import cv2
import pytesseract
from fishy.helper.downloader import download_file_from_google_drive
from fishy.helper.helper import get_documents
directory = os.path.join(os.environ["APPDATA"], "Tesseract-OCR")
def downlaoad_and_extract_tesseract():
logging.info("Tesseract-OCR downlaoding, Please wait...")
f = tempfile.NamedTemporaryFile(delete=False)
download_file_from_google_drive("16llzcBlaCsG9fm-rY2dD4Gvopnhm3XoE", f)
f.close()
logging.info("Tesseract-OCR downloaded, now installing")
with ZipFile(f.name, 'r') as z:
z.extractall(path=directory)
logging.info("Tesseract-OCR installed")
def is_tesseract_installed():
return os.path.exists(os.path.join(os.environ["APPDATA"], "Tesseract-OCR"))
# noinspection PyBroadException
def get_values_from_image(img):
try:
pytesseract.pytesseract.tesseract_cmd = directory + '/tesseract.exe'
tessdata_dir_config = f'--tessdata-dir "{directory}" -c tessedit_char_whitelist=0123456789.'
text = pytesseract.image_to_string(img, lang="eng", config=tessdata_dir_config)
text = text.replace(" ", "")
vals = text.split(":")
return float(vals[0]), float(vals[1]), float(vals[2])
except Exception:
logging.error("Couldn't read coods, make sure 'crop' calibration is correct")
cv2.imwrite(os.path.join(get_documents(), "fishy_failed_reads", f"{datetime.now()}.jpg"), img)
return None