本文整理汇总了Python中tesserocr.PyTessBaseAPI方法的典型用法代码示例。如果您正苦于以下问题:Python tesserocr.PyTessBaseAPI方法的具体用法?Python tesserocr.PyTessBaseAPI怎么用?Python tesserocr.PyTessBaseAPI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tesserocr
的用法示例。
在下文中一共展示了tesserocr.PyTessBaseAPI方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import tesserocr [as 别名]
# 或者: from tesserocr import PyTessBaseAPI [as 别名]
def setUp(self):
if pil_installed:
with open(self._image_file, 'rb') as f:
self._image = Image.open(f)
self._image.load()
self._api = tesserocr.PyTessBaseAPI(init=True)
示例2: image_ocr
# 需要导入模块: import tesserocr [as 别名]
# 或者: from tesserocr import PyTessBaseAPI [as 别名]
def image_ocr(path, lang):
logger.info("opening %s", path)
with PyTessBaseAPI() as api:
api.SetImageFile(path)
text = api.GetUTF8Text().strip()
return text
示例3: post
# 需要导入模块: import tesserocr [as 别名]
# 或者: from tesserocr import PyTessBaseAPI [as 别名]
def post(self, request, *args, **kwargs):
with PyTessBaseAPI() as api:
with Image.open(request.FILES['image']) as image:
sharpened_image = image.filter(ImageFilter.SHARPEN)
api.SetImage(sharpened_image)
utf8_text = api.GetUTF8Text()
return JsonResponse({'utf8_text': utf8_text})
示例4: get_api
# 需要导入模块: import tesserocr [as 别名]
# 或者: from tesserocr import PyTessBaseAPI [as 别名]
def get_api(self, languages):
if not hasattr(self.thread, 'api'):
from tesserocr import PyTessBaseAPI, PSM
api = PyTessBaseAPI(lang=languages)
api.SetPageSegMode(PSM.AUTO_OSD)
self.thread.api = api
return self.thread.api
示例5: get_ocr
# 需要导入模块: import tesserocr [as 别名]
# 或者: from tesserocr import PyTessBaseAPI [as 别名]
def get_ocr():
"""Check if OCR service is available; else throw an error"""
if not hasattr(settings, '_ocr'):
try:
from tesserocr import PyTessBaseAPI, PSM, OEM
log.info("Configuring OCR engine...")
settings._ocr = PyTessBaseAPI(lang=LANGUAGES,
oem=OEM.LSTM_ONLY,
psm=PSM.AUTO_OSD)
except ImportError:
log.warning("OCR engine is not available")
settings._ocr = None
return settings._ocr