Skip to content

Commit

Permalink
make track script capable of working independently of the rest of the…
Browse files Browse the repository at this point in the history
… pipeline
  • Loading branch information
aryarm committed Nov 3, 2018
1 parent 9f3c49b commit c471896
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion track.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from constants import *
import matlab.engine
import numpy as np
from vid_meta_data import *
import argparse


def trackOneClip(vidPath, cushion, W, H, minBlob, vidExport, result_path):
Expand Down Expand Up @@ -55,7 +57,54 @@ def trackOneClip(vidPath, cushion, W, H, minBlob, vidExport, result_path):
track_result = np.append(track_result, [[vidPath, directionX, directionY]], axis=0)
# return the data without its header
return track_result[1:,]
return []
return np.array([])

def main():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--i',
dest = 'cropVid',
required = True,
type=str,
help='path to a video to track')
arg_parser.add_argument('--o',
dest = 'result_path',
required = True,
type=str,
help='path to a directory in which to dump result videos')
arg_parser.add_argument('--r',
dest = 'result',
required = True,
type=str,
help='path of array of results to output')
arg_parser.add_argument('--c',
dest = 'cushion',
type=int,
default=10,
help='number of pixels as padding (default = 10)')
arg_parser.add_argument('--m',
dest = 'minBlob',
type=int,
default=35,
help='minimum blob area in pixels (default = 35)')
arg_parser.add_argument('--e',
dest = 'export',
type=bool,
default=False,
help='do we export result video (default = False)')
args = arg_parser.parse_args()

# track ants in each of the cropped videos
result_array = np.array([["fName", "X", "Y"]])
print "Tracking ants in " + args.cropVid
# get heigh and width of video
H, W = findVideoMetada(args.cropVid)
# call matlab to track ants in a single cropped video
track_result = trackOneClip(args.cropVid, args.cushion, W, H, args.minBlob, args.export, args.result_path)
# keep track of the tracking results in a np array
if track_result.size:
result_array = np.concatenate((result_array, track_result), axis=0)
# save the tracking results to disk
np.savetxt(args.result, result_array, delimiter= ',', fmt='%s')

if __name__== "__main__":
main()

0 comments on commit c471896

Please sign in to comment.