logger.error("error in loading image:{}".format(image_file))
returnNone
ifisinstance(img,np.ndarray)andlen(img.shape)==2:
img=cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
returnimg
classPaddleOCR(predict_system.TextSystem):
def__init__(self,**kwargs):
"""
...
...
@@ -482,7 +509,7 @@ class PaddleOCR(predict_system.TextSystem):
rec: use text recognition or not. If false, only det will be exec. Default is True
cls: use angle classifier or not. Default is True. If true, the text with rotation of 180 degrees can be recognized. If no text is rotated by 180 degrees, use cls=False to get better performance. Text with rotation of 90 or 270 degrees can be recognized even if cls=False.
"""
assertisinstance(img,(np.ndarray,list,str))
assertisinstance(img,(np.ndarray,list,str,bytes))
ifisinstance(img,list)anddet==True:
logger.error('When input a list of images, det must be false')
exit(0)
...
...
@@ -491,22 +518,8 @@ class PaddleOCR(predict_system.TextSystem):
'Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process'
)
ifisinstance(img,str):
# download net image
ifimg.startswith('http'):
download_with_progressbar(img,'tmp.jpg')
img='tmp.jpg'
image_file=img
img,flag,_=check_and_read(image_file)
ifnotflag:
withopen(image_file,'rb')asf:
np_arr=np.frombuffer(f.read(),dtype=np.uint8)
img=cv2.imdecode(np_arr,cv2.IMREAD_COLOR)
ifimgisNone:
logger.error("error in loading image:{}".format(image_file))