paddleOCR中示例draw_ocr出错问题解决

from PIL import Image

image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores)
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

上面代码是原始示例代码,运行新版本的paddleocr会报错:

Traceback (most recent call last):
    im_show = draw_ocr(image, boxes, txts, scores)
  File "\lib\site-packages\paddleocr\tools\infer\utility.py", line 382, in draw_ocr
    if scores is not None and (scores[i] < drop_score or
TypeError: '<' not supported between instances of 'tuple' and 'float'

修改如下:

 

from PIL import Image
image = Image.open(img_path).convert('RGB')
boxes = [detection[0] for line in result for detection in line] # Nested loop added
txts = [detection[1][0] for line in result for detection in line] # Nested loop added
scores = [detection[1][1] for line in result for detection in line] # Nested loop added
im_show = draw_ocr(image, boxes, txts, scores)
im_show = Image.fromarray(im_show)
im_show.save('test.jpg')

你可能感兴趣的:(python,开发语言)