Created
February 25, 2018 11:37
-
-
Save cheind/9850e35bb08cfe12500942fb8b55531f to your computer and use it in GitHub Desktop.
BeaverDam dense annotation viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import json | |
import pandas as pd | |
import numpy as np | |
def convert_to_pandas(content): | |
events = [] | |
for obj in content: | |
for f in obj['frames']: | |
events.append({ | |
'fid' : f['frameid'], | |
'oid' : obj['id'], | |
'type' : obj['type'], | |
'state' : f['state'], | |
'x' : f['x'], | |
'y' : f['y'], | |
'w' : f['w'], | |
'h' : f['h'], | |
}) | |
df = pd.DataFrame(events) | |
return df | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser(description='Show dense annotations') | |
parser.add_argument('-video', help='Input video file', required=True) | |
parser.add_argument('-ann', help='Dense annotation file', required=True) | |
args = parser.parse_args() | |
with open(args.ann) as fh: | |
content = json.load(fh) | |
df = convert_to_pandas(content) | |
cap = cv2.VideoCapture(args.video) | |
idx = 0 | |
while(True): | |
ret, frame = cap.read() | |
for _, obj in df[(df.fid == idx)].iterrows(): | |
xywh = np.squeeze(obj[['x', 'y', 'w', 'h']].values.astype(int)) | |
cv2.rectangle(frame, (xywh[0],xywh[1]), (xywh[0]+xywh[2],xywh[1]+xywh[3]), (255,0,0), 2, -1) | |
# Display the resulting frame | |
cv2.imshow('frame',frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
idx += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment