遍历预测坐标值在图像上绘制矩形框(目标跟踪实验)

格式输出为OTB格式,代码如下:

# 定义图像文件夹路径和对应txt文件的前缀
image_folder = 'D:/traker_resuts/rpnrfnttban9-1/'#原始图像文件夹
txt_file = 'D:/traker_resuts/tt/test_txt/ours11-1.txt'#预测txt文件

# 获取所有图像文件的路径
image_files = [os.path.join(image_folder, f) for f in os.listdir(image_folder) if
               f.endswith('.jpg')]  # 假设图像文件以.jpg为扩展名

# 读取txt文件,获取所有标注的坐标信息
with open(txt_file, 'r') as f:
    annotations = f.readlines()

# 遍历所有行和所有图像
for index, annotation in enumerate(annotations):
    # 获取当前行的数
    print(index)
    if 'nan' in annotation:
        x1, y1, w, h =0,0,0,0
    else:
        x1, y1, w, h = map(int, annotation.strip().split(','))

        # 获取当前图像文件的路
    #current_image = image_files[index]#按图像文件夹索引
    current_image = image_folder+str(index)+'.jpg'#image_files[index]#按图像名称0,1,2..的顺序。

    # 加载图像
    image = cv2.imread(current_image)
    x2 = x1 + w
    y2 = y1 + h

    # 在图像上绘制矩形框(假设第五行包含四个整数,分别代表矩形左上角和右下角的坐标(x1, y1, x2, y2))
    cv2.rectangle(image, (x1, y1), (x2, y2), (0,0,255), 2)  # 在图像上绘制红色矩形框

    # 保存绘制了矩形框的图像文件(不覆盖原图)

    output_file = 'D:/traker_resuts/rpnrfnttbanour9-1/' + str(index) + '.jpg'  # 输出图像文件"
    cv2.imwrite(output_file, image)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值