本文整理匯總了Python中tesserocr.image_to_text方法的典型用法代碼示例。如果您正苦於以下問題:Python tesserocr.image_to_text方法的具體用法?Python tesserocr.image_to_text怎麽用?Python tesserocr.image_to_text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tesserocr
的用法示例。
在下文中一共展示了tesserocr.image_to_text方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _predict
# 需要導入模塊: import tesserocr [as 別名]
# 或者: from tesserocr import image_to_text [as 別名]
def _predict(self, x):
text = tesserocr.image_to_text(x.convert('L'), lang='eng')
return text
示例2: image_has_text
# 需要導入模塊: import tesserocr [as 別名]
# 或者: from tesserocr import image_to_text [as 別名]
def image_has_text(image: LIST_3D):
"""
Parameters
----------
image
A 3D array with the RGB values for the image
Returns
-------
True if the image has text, False otherwise
"""
image = Image.fromarray(image)
text = tesserocr.image_to_text(image)
return True if len(text.strip()) > 0 else False
示例3: test_image
# 需要導入模塊: import tesserocr [as 別名]
# 或者: from tesserocr import image_to_text [as 別名]
def test_image(self):
"""Test SetImage and GetUTF8Text."""
self._api.SetImage(self._image)
text = self._api.GetUTF8Text()
self.assertIn('quick', text)
text2 = tesserocr.image_to_text(self._image)
self.assertEqual(text, text2)
示例4: _process_image
# 需要導入模塊: import tesserocr [as 別名]
# 或者: from tesserocr import image_to_text [as 別名]
def _process_image(self, yara_rule: str, save_context: bool) -> None:
"""
Perform OCR and yara rule matching as a worker.
process_image() is used by the run() method to create multiple worker processes for
parallel execution. process_image normally will not be called directly.
Arguments:
yara_rule -- File path pointing to a Yara rule file
"""
context = None
handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter(
'%(log_color)s%(levelname)s:%(name)s:%(message)s'))
# Creates a logger object for the individual workers that contains the PID as part of the message header
worker_logger = colorlog.getLogger('worker_'+str(os.getpid()))
worker_logger.addHandler(handler)
worker_logger.setLevel(self.logger.level)
worker_logger.info('PID {0} created to process queue'.format(str(os.getpid())))
while True:
try:
image, filepath = self.q.get(timeout=.25)
except Empty:
if self.total_added_to_queue[0] == self.total_items_to_queue[0]:
worker_logger.debug('Queue Empty PID %d exiting' % os.getpid())
return
else:
worker_logger.debug('Queue still loading')
continue
ocrtext = tesserocr.image_to_text(image)
try:
rules = yara.compile(yara_rule)
except yara.Error:
worker_logger.error('Invalid rule file/rule file not found: {0}'.format(yara_rule))
matches = rules.match(data=ocrtext)
# If there is a match, store the filename and the rule in a dictionary local to this process.
# Create an editable copy of the master manager dict.
with self.lock:
local_results_dict = self.matchedfiles[0]
if matches:
if save_context:
context = ocrtext
for x in matches:
try:
local_results_dict[filepath].append((x.rule, context))
except KeyError:
local_results_dict[filepath] = [(x.rule, context)]
self.matchedfiles[0] = local_results_dict
self.queue_items_completed[0] += 1
self.q.task_done()