Skip to content

ALPR_inference中函数部分代码修改 #929

Open
@jiangjq907

Description

@jiangjq907

def get_best_ocr(preds, rec_conf, ocr_res, track_id):
for info in preds:
# Check if it is current track id
if info['track_id'] == track_id:
# Check if the ocr confidenence is maximum or not
if info['ocr_conf'] < rec_conf:
info['ocr_conf'] = rec_conf
info['ocr_txt'] = ocr_res
else:
rec_conf = info['ocr_conf']
ocr_res = info['ocr_txt']
break
return preds, rec_conf, ocr_res
原函数中的逻辑不正确实际上只修改了第一个元素,不会遍历寻找更高置信度的元素,所以进行以下修改:
def update_best_ocr(preds, rec_conf, ocr_res, track_id):
updated = False # 添加一个标志,表示是否更新了信息

for info in preds:
    # 查找并更新指定track_id的信息
    if info['track_id'] == track_id:
        # 直接更新OCR信息,不比较,假设传入的rec_conf和ocr_res是最新的
        info['ocr_conf'] = rec_conf
        info['ocr_txt'] = ocr_res
        updated = True  # 标记信息已被更新
        break  # 找到并更新后,不需要继续循环

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions