根据跟踪结果画框图Python代码

ground_truth_box.py

import cv2
data_path = r"E:/shipinjihe/WILD_ANIMAL/AnimalData/TheGreatFox/groundtruth_rect.txt"   #文本文档所在目录v     groundtruth_rect
image_path = "E:/shipinjihe/WILD_ANIMAL/AnimalData/TheGreatFox/img2"   #图片所在目录,使用“/”,而不是“\”
with open(data_path) as fb:                                               #将数据逐行读取
    lines = fb.readlines()
for i in range(1,1527):
    if i<10:                                                    #对图片和数据进行循环(注意:第二个数是 图片数+1)
        image_path1 = image_path+"/000"+str(i)+".jpg"                            #图片的绝对路径                        
    elif i<100:
        image_path1 = image_path+"/00"+str(i)+".jpg"
    elif i<1000:
        image_path1 = image_path+"/0"+str(i)+".jpg"
    else:
        image_path1 = image_path+"/"+str(i)+".jpg"
    image = cv2.imread(image_path1)                                       #循环读取图片
    value = lines[i-1].split(',')                                         #将数据按“,”进行分割
    result = [i.rstrip() for i in value]
    x_min = round(float(result[0]))                                               #以下四行建立方框的坐标点
    y_min = round(float(result[1]))
    x_max = round(float(result[0])) + round(float(result[2]))
    y_max = round(float(result[1])) + round(float(result[3]))
    print(x_min, y_min, x_max, y_max)
    first_point = (x_min, y_min)
    last_point = (x_max, y_max)
    cv2.rectangle(image, first_point, last_point,(0,0,255), 2)         #在图片中构建方框
    cv2.imwrite(image_path1, image)                                       #保存图片

    # BGR  红gt  (0, 0, 255)  绿stark (0, 255, 0)  紫 transt (240, 32, 160)  青siamban (139, 139, 0)  黄GFSDCF(0,255,255)    蓝ASRCF(255,0,0)    橙STRCF(0,165,255)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值