类型错误:'<' not supported between instances of 'tuple' and 'float'

问题描述 投票:0回答:1
from PIL import Image, ImageDraw, ImageFont
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]
font = ImageFont.load_default()
im_show = draw_ocr(image, boxes, txts, scores,font_path='/usr/share/fonts/truetype/humor-     sans/Humor-Sans.ttf' )
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

我一直在尝试执行一个从在线 github 存储库中找到的 python 项目。它用于利用 paddleocr 实现 OCR 工具。上述代码中的 result 变量等于: result = ocr.ocr(img_path, cls=True) 其中“img_path”是图像的路径。它的基本作用是使用draw_ocr fn 绘制输出,以生成突出显示字符的输出并从图像生成其文本表示形式。但是当我运行上面的代码时,我收到错误: 在draw_ocr(图像,框,txt,分数,drop_score,font_path)中 box_num = len(盒子) 对于范围内的 i(box_num): 如果分数不为 None 且 (scores[i] < drop_score or math.isnan(scores[i])): continue

    TypeError: '<' not supported between instances of 'tuple' and 
    'float'

boxes、txts和scores的值分别是: box = [[[[56.0, 124.0], [444.0, 127.0], [444.0, 162.0], [56.0, 159.0]], ('Hanolwrrten 使用机器人', 0.8703486323356628)]] txt = [[[41.0, 167.0], [554.0, 165.0], [554.0, 210.0], [41.0, 212.0]]] 分数 = [('使用的随机写入机器', 0.9404943585395813)]

不知道我哪里错了。尝试将上述输入中的元组转换为列表,但无济于事。任何意见都将不胜感激!

python machine-learning ocr paddle-paddle paddleocr
1个回答
0
投票

我认为错误意味着这段代码:

scores[i] < drop_score
scores[i]
是一个有意义的元组。变量
scores
是列表中的元组,因此
scores[i]
实际上指的是该元组。

假设您想要元组内的数字 (

0.9404943585395813
),则必须通过索引访问元组中的元素。像
scores[i][1]
scores[i][-1]
这样的东西就可以了。但是,元组中数字的位置可能会根据该数字的生成方式而改变。

因此,将这部分代码:

scores[i] < drop_score
替换为
scores[i][1] < drop_score
应该可以。让我知道这是否是您的意图

© www.soinside.com 2019 - 2024. All rights reserved.