def get_hof(name):
print name
FLOW_DIR = 'data/of_' + args.domain + '/' + name + '/'
BOXES_DIR = 'data/feature_' + args.domain + \
'_' + str(args.n_boxes) + 'boxes/' + name + '/'
n_frames = len(glob.glob(FLOW_DIR + '*.png'))
# init boxes
clip_boxes_index = 1
clip_boxes = np.load(BOXES_DIR + 'roislist{:04d}.npy'.format(clip_boxes_index))
# init hof
hof_shape = (50, args.n_boxes, 12)
hof = np.zeros(hof_shape)
for i in xrange(1, n_frames+1):
print "{}, Flow {}, ".format(name, i)
# boxes
new_clip_boxes_index = (i-1) / 50 + 1
if clip_boxes_index != new_clip_boxes_index:
# 1.1 save hof and init a new one
np.save(BOXES_DIR + 'hof{:04d}.npy'.format(clip_boxes_index), hof)
hof = np.zeros(hof_shape)
# 2.1 update clip_boxes
clip_boxes_index = new_clip_boxes_index
clip_boxes = np.load(BOXES_DIR + 'roislist{:04d}.npy'.format(clip_boxes_index))
flow_img = np.array(cv2.imread(FLOW_DIR + '{:06d}.png'.format(i)), dtype=np.float32)
frame_boxes = clip_boxes[(i-1) % 50].astype(int)
for box_id, (xmin, ymin, xmax, ymax) in enumerate(frame_boxes):
xmin, ymin, xmax, ymax = preprocess_box(xmin, ymin, xmax, ymax)
box_flow_img = flow_img[ymin:ymax, xmin:xmax, :]
hof[(i-1) % 50][box_id], _ = flow_to_hist(box_flow_img)
# save latest hof
np.save(BOXES_DIR + 'hof{:04d}.npy'.format(clip_boxes_index), hof)
评论列表
文章目录