Skip to content

Instantly share code, notes, and snippets.

@kndt84
Last active August 4, 2017 05:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kndt84/891dcbc0fff6528eccd08fa39bd15e21 to your computer and use it in GitHub Desktop.
Add unixtime to first column
#!/usr/bin/python
import csv
import sys
import re
fps=10
filename=sys.argv[1]
start_unixtime=int(re.search(r'(\d+)\.txt', filename).group(1))
for i, line in enumerate(open(filename, 'r')):
if i==0:
continue # skip first row
elements = line.rstrip().split(' ')
unix_time = start_unixtime+int(elements[0])/float(fps)
elements.insert(0, str(unix_time))
newline=','.join(elements)
print(newline)
@kndt84
Copy link
Author

kndt84 commented Aug 4, 2017

echo "unixtime,frame_no,tracking_id,type,confidence,x,y,w,h" > hoge.csv
python add_unixtime.py * >> hoge.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment