首页 > 解决方案 > 如何在 Heroku 中使用 tesseract 和 ocr?

问题描述

我按照这篇文章,在代码中添加了 tesseract_cmd,添加了 Aptfile,但部署后出现问题:

import cv2
import os
class TestingView(APIView):
    def post(self, req):
        print(req.FILES)
        crop_img = req.FILES["ok"]
        print(crop_img)
        file_loc = "media/"
        fs = FileSystemStorage(location=file_loc)
        filename = fs.save(crop_img.name, crop_img)
        crop_img = cv2.imread(file_loc+"crop_12_.png")
        print(os.getcwd())
        f = open("ok.txt", "w+")
        f.write("shiv")
        f.close()
        pytesseract.pytesseract.tesseract_cmd = "/app/.apt/usr/share/tesseract-ocr/4.00/tessdata"
        output = pytesseract.image_to_string(crop_img, lang='hin') #, config=)
        text = "ok"
        return Response({"ok": output})
        # return Response({"ok": text})

错误

PermissionError at /testing/
[Errno 13] Permission denied: '/app/.apt/usr/share/tesseract-ocr/4.00/tessdata'

build_pack 和 TESSDATA_PREFIX=/app/.apt/usr/share/tesseract-ocr/4.00/tessdata 也添加了。任何解决方案?

标签: pythonherokutesseract

解决方案


推荐阅读