本文整理匯總了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