from paddleocr import PaddleOCR | |
def ocr_with_paddle(img): | |
""" | |
Perform Optical Character Recognition (OCR) on the input image. | |
:param img: The input image for OCR | |
:return: The recognized text from the input image, or 'No text detected' if no text is found | |
""" | |
finaltext = '' | |
ocr = PaddleOCR(lang='en', use_angle_cls=True) | |
result = ocr.ocr(img) | |
try: | |
for i in range(len(result[0])): | |
text = result[0][i][1][0] | |
finaltext += ' ' + text | |
return finaltext | |
except TypeError: | |
return 'No text detected' |