行人追踪标注追踪颜色框

来源:互联网 发布:手机淘宝店铺招牌图片 编辑:程序博客网 时间:2024/04/29 00:57

前言

在行人追踪过程中,需要对追踪结果根据id和位置信息标注追踪颜色框,更好的展示追踪效果。此前在测试开源项目时,写了一个追踪标注代码,以此分享。

准备

ubuntu14.04+python2.7
(其他平台一样能跑,配置相关库即可)
开源代码:https://github.com/abewley/sort

效果展示

这里写图片描述

代码

#coding=utf-8import osimport sysfrom PIL import Image,ImageDrawrect_dict = {}color_list = ['blue', 'red', 'yellow', 'green', 'orange', 'white', 'pink', 'magenta', 'cyan']f = open("/home/wuq/data/317.txt").readlines()for line in f:    line = line.split(',')    frame=int(line[0])-25200    str_frame=str(frame)    list=[str_frame,line[1],line[2],line[3],line[4],line[5]]    rect_dict.setdefault(list[0], [])    id, x, y, w, h = list[1], list[2], list[3], list[4], list[5]    rect_dict[list[0]].append([int(id), x, y, w, h])path = "/home/wuq/photo/"dirs = os.listdir( path )for file in dirs:    im = Image.open(path + file)    flag = file.split(".")[0]       for rect_info in rect_dict[flag]:            a = float(x)        b = float(y)        c = float(x)+float(w)        d = float(y) + float(h)                id, x, y, w, h = rect_info                color = color_list[id % len(color_list)]        draw = ImageDraw.Draw(im)        draw.rectangle((a,b,c,d),outline = color)                draw.rectangle((a+1,b+1,c+1,d+1),outline = color)                draw.rectangle((a+2,b+2,c+2,d+2),outline = color)                im.save("/home/wuq/photo1/"+file)
原创粉丝点击