做android项目时需要用到图片识别文字,写了一个python代码实现了,在android studio里用的Chaquopy方法,然后用了tesseract包,但是一直报错tesseract is not installed or it's not in your PATH。在本地的python环境是可以运行python文件的,转到android studio里就不行了。
python代码
from java import jclass
import pytesseract
from PIL import Image
import xlrd
from os.path import dirname, join
def imagetest():
address = join(dirname(__file__), "test.jpg")
image = Image.open(address)
tessdata_dir_config =join(dirname(__file__),'--tessdata-dir "./tessdata"')
codeTrain = pytesseract.image_to_string(image, config=tessdata_dir_config, lang = "train")
codeNew = pytesseract.image_to_string(image, config=tessdata_dir_config, lang = "new")
codeNum = pytesseract.image_to_string(image, config=tessdata_dir_config, lang = "num")
codeTry = pytesseract.image_to_string(image, config=tessdata_dir_config, lang = "try")
报错提示
Caused by: com.chaquo.python.PyException: TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
at <python>.pytesseract.pytesseract.run_tesseract(pytesseract.py:258)
at <python>.pytesseract.pytesseract.run_and_get_output(pytesseract.py:286)
at <python>.pytesseract.pytesseract.<lambda>(pytesseract.py:419)
at <python>.pytesseract.pytesseract.image_to_string(pytesseract.py:416)
at <python>.hello.imagetest(hello.py:11)
也是刚刚用这种方法,完全没有解决思路,查了网上的方法,似乎都是针对本地环境,本地上也下载了Tesseract-OCR才解决那个找不到的问题,但是不知道在as里该怎么解决这个问题