使用圖像調用下面的代碼會給我提供正確的結果。 但是,由於未知原因,字符串相等失敗。使用tesseract和opencv進行python字符串比較
def image_to_string(im, cleanup = cleanup_scratch_flag):
"""Converts im to file, applies tesseract, and fetches resulting text.
If cleanup=True, delete scratch files after operation."""
try:
util.image_to_scratch(im, scratch_image_name)
call_tesseract(scratch_image_name, scratch_text_name_root)
text = util.retrieve_text(scratch_text_name_root)
finally:
if cleanup:
util.perform_cleanup(scratch_image_name, scratch_text_name_root)
return text
cityname=image_to_string(im)
print cityname # this statement prints 'London' without quotes
print cityname=='London' # This statement is always false
即尖端helped.There有一些額外的換行序列 – addcolor