예제 #1
0
def prepare_vid(cropped_video, infile, temp_dir, crop):
    """get FIJI compatible avi from video"""
    ffmpeg = Ffmpeg(infile, temp_dir + cropped_video)
    ffmpeg.pix_fmt = "nv12"
    ffmpeg.f = "avi"
    ffmpeg.vcodec = "rawvideo"
    ffmpeg.filter = "crop=" + crop
    ffmpeg.run()
예제 #2
0
def main():
    """main function to track fish"""
    parser = argparse.ArgumentParser(description="Tracks adult fish")
    # add options for argument parser
    parser.add_argument("in_path",
                        help="Path to the video directory.")
    parser.add_argument("out_path",
                        help="Directory for results. Should be empty.")
    parser.add_argument("-x", "--keep_temp", action="store_true",
                        help="Keep temporary folder after execution.")
    parser.add_argument("--visual", action="store_true",
                        help="shows a visual representation of the tracking progress.")

    # parse arguments from command line
    args = parser.parse_args()
    # get all file names and directories ready
    out_dir, temp_dir, video_bases, videos = housekeeping(args)
    borders = []
    for i in range(len(videos)):
        v = videos[i]
        get_borders(borders, temp_dir, v)

    for i in range(len(videos)):
        vbn = video_bases[i]
        v = videos[i]
        scaled_video = "scaled_" + vbn + ".avi"
        ffmpeg = Ffmpeg(v, os.path.join(temp_dir, scaled_video))
        ffmpeg.f = "avi"
        ffmpeg.vcodec = "libx264rgb"
        ffmpeg.width = 480
        ffmpeg.run()

    for i in range(len(videos)):
        vbn = video_bases[i]
        pts = tracker(args, temp_dir, vbn)
        border = borders[i]
        tracks_lower, tracks_upper = split_tracks(border, pts)
        analysis = Analysis(tracks_lower, tracks_upper, px_size=0.06)
        analysis.analyze(os.path.join(out_dir, 'stats.txt'), vbn, vel=True)

    if not args.keep_temp:
        shutil.rmtree(temp_dir)