62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
|
import os
|
||
|
from tracker import performMarkerTracking
|
||
|
|
||
|
|
||
|
ROOT_DATA_DIR = '/home/mmbrian/HiWi/etra2016_mohsen/code/recording/data/participants'
|
||
|
SQUARE_SIZE = '0.16'
|
||
|
|
||
|
def main(force = False):
|
||
|
'''
|
||
|
Processes all the participants recordings and performs marker tracking on each video and stores marker data in a npy file near the video
|
||
|
'''
|
||
|
c = 0
|
||
|
for d1 in os.listdir(ROOT_DATA_DIR):
|
||
|
if d1.startswith('p'): # every participant
|
||
|
d2 = os.path.join(ROOT_DATA_DIR, d1) # .../pi/
|
||
|
d2 = os.path.join(d2, os.listdir(d2)[0]) # .../pi/../
|
||
|
for d3 in os.listdir(d2): # every recording
|
||
|
d4 = os.path.join(d2, d3) # .../pi/../00X/
|
||
|
print '> Processing', d4
|
||
|
frames_dir = os.path.join(d4, '_aruco_frames.npy')
|
||
|
if os.path.isfile(frames_dir):
|
||
|
if not force: # already processed this recording
|
||
|
print '> Recording already processed...'
|
||
|
continue
|
||
|
else: # video processed, but forced to process again
|
||
|
# remove old file
|
||
|
print '> Reprocessing file:', frames_dir
|
||
|
print '> Removing old marker file...'
|
||
|
os.remove(frames_dir)
|
||
|
|
||
|
world_path = os.path.join(d4, 'world.avi')
|
||
|
|
||
|
log_dir = os.path.join(d4, '_ArUco.log')
|
||
|
read_log = False
|
||
|
if os.path.isfile(log_dir):
|
||
|
read_log = True
|
||
|
else: # no log available > process video
|
||
|
if not os.path.isfile(world_path): # .avi file exists
|
||
|
# Creating avi
|
||
|
print '> AVI video does not exists, generating it from mp4 source file...'
|
||
|
os.popen('avconv -i ' + os.path.join(d4, 'world.mp4') + ' -c:a copy -c:v copy ' + world_path + ' -v quiet')
|
||
|
|
||
|
# Perform tracking...
|
||
|
performMarkerTracking(read_from_log = read_log, log = True, log_dir = log_dir,
|
||
|
recording_video = world_path + ' ', frames_dir = frames_dir,
|
||
|
square_size = SQUARE_SIZE) # in case of relocating camera.yml input the new path as cam_math
|
||
|
if not read_log:
|
||
|
# Removing avi file
|
||
|
print '> Removing avi file:', world_path
|
||
|
os.remove(world_path)
|
||
|
c += 1
|
||
|
print '> Processed %s recordings so far...' % c
|
||
|
# print '> Halting...'
|
||
|
# return
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main(force=False)
|
||
|
print 'Finished.'
|
||
|
|
||
|
|
||
|
|