def __init__(self): self.frames = None self.truth = None self.tracked = None if not os.path.exists(config.DATA_FOLDER): print 'Error: folder not found' return repo = Repository.load(config.DATA_FOLDER) start_time = datetime(config.DATE[0], config.DATE[1], config.DATE[2], config.TIME[0], config.TIME[1], tzinfo=pytz.utc) end_time = datetime(config.DATE[0], config.DATE[1], config.DATE[2], config.TIME[0], config.TIME[1] + 1, tzinfo=pytz.utc) fnames = repo.iter_fnames(begin=start_time, end=end_time) for fname in fnames: frame_container = load_frame_container(fname) cam = frame_container.camId self.frames = list(frame_container.frames) # break because we only load the first fname break if not os.path.exists(config.TRACKED_PATHS_FILE): print 'Error: file not found' return with open(config.TRACKED_PATHS_FILE, 'rb') as tracked_paths_file: tracked_input = pickle.load(tracked_paths_file) self.tracked = tracked_input['paths'] if not os.path.exists(config.TRUTH_PATHS_FILE): print 'Error: file not found' return with open(config.TRUTH_PATHS_FILE, 'rb') as truth_paths_file: truth_input = pickle.load(truth_paths_file) self.truth = truth_input['paths']
def __init__( self ): self.frames = None self.truth = None self.tracked = None if not os.path.exists( config.DATA_FOLDER ): print 'Error: folder not found' return repo = Repository.load( config.DATA_FOLDER ) start_time = datetime( config.DATE[ 0 ], config.DATE[ 1 ], config.DATE[ 2 ], config.TIME[ 0 ], config.TIME[ 1 ], tzinfo=pytz.utc ) end_time = datetime( config.DATE[ 0 ], config.DATE[ 1 ], config.DATE[ 2 ], config.TIME[ 0 ], config.TIME[ 1 ]+1, tzinfo=pytz.utc ) fnames = repo.iter_fnames( begin=start_time, end=end_time ) for fname in fnames: frame_container = load_frame_container( fname ) cam = frame_container.camId self.frames = list( frame_container.frames ) # break because we only load the first fname break if not os.path.exists( config.TRACKED_PATHS_FILE ): print 'Error: file not found' return with open( config.TRACKED_PATHS_FILE, 'rb' ) as tracked_paths_file: tracked_input = pickle.load( tracked_paths_file ) self.tracked = tracked_input[ 'paths' ] if not os.path.exists( config.TRUTH_PATHS_FILE ): print 'Error: file not found' return with open( config.TRUTH_PATHS_FILE, 'rb' ) as truth_paths_file: truth_input = pickle.load( truth_paths_file ) self.truth = truth_input[ 'paths' ]
def __init__(self): self.frames = None self.source = None if not os.path.exists(config.DATA_FOLDER): print 'Error: folder not found' return try: repo = Repository.load(config.DATA_FOLDER) start_time = datetime(config.DATE[0], config.DATE[1], config.DATE[2], config.TIME[0], config.TIME[1], tzinfo=pytz.utc) end_time = datetime(config.DATE[0], config.DATE[1], config.DATE[2], config.TIME[0], config.TIME[1] + 1, tzinfo=pytz.utc) fnames = repo.iter_fnames(begin=start_time, end=end_time) for fname in fnames: frame_container = load_frame_container(fname) cam = frame_container.camId self.frames = list(frame_container.frames) self.source = frame_container.dataSources[0].filename # break because we only load the first fname break except: pass
def __init__( self ): self.frames = None self.source = None if not os.path.exists( config.DATA_FOLDER ): print 'Error: folder not found' return try: repo = Repository.load( config.DATA_FOLDER ) start_time = datetime( config.DATE[ 0 ], config.DATE[ 1 ], config.DATE[ 2 ], config.TIME[ 0 ], config.TIME[ 1 ], tzinfo=pytz.utc ) end_time = datetime( config.DATE[ 0 ], config.DATE[ 1 ], config.DATE[ 2 ], config.TIME[ 0 ], config.TIME[ 1 ]+1, tzinfo=pytz.utc ) fnames = repo.iter_fnames( begin=start_time, end=end_time ) for fname in fnames: frame_container = load_frame_container( fname ) cam = frame_container.camId self.frames = list( frame_container.frames ) self.source = frame_container.dataSources[ 0 ].filename # break because we only load the first fname break except: pass
def main(): # loading data if not os.path.exists( config.DATA_FOLDER ): print 'Error: folder not found' return dset_store = ds.DetectionSetStore() repo = Repository.load( config.DATA_FOLDER ) start_time = datetime( config.DATE[ 0 ], config.DATE[ 1 ], config.DATE[ 2 ], config.TIME[ 0 ], config.TIME[ 1 ], tzinfo=pytz.utc ) end_time = datetime( config.DATE[ 0 ], config.DATE[ 1 ], config.DATE[ 2 ], config.TIME[ 0 ], config.TIME[ 1 ]+1, tzinfo=pytz.utc ) fnames = repo.iter_fnames( begin=start_time, end=end_time ) for fname in fnames: frame_container = load_frame_container( fname ) cam = frame_container.camId dset_store.source = frame_container.dataSources[ 0 ].filename previous_timestamp = None frame_index = config.FRAME_START for frame in list( frame_container.frames )[ config.FRAME_START : config.FRAME_END + 1 ]: timestamp = ds.TimeStamp( frame_index, cam ) timestamp.connect_with_previous( previous_timestamp ) previous_timestamp = timestamp dset = ds.DetectionSet() dset_store.store[ timestamp ] = dset data = convert_frame_to_numpy( frame ) for detection_data in data: dset.add_detection( ds.Detection( detection_data[ 'idx' ], timestamp, np.array( [ detection_data[ 'ypos' ], detection_data[ 'xpos' ] ] ), # rotated, otherwise will be portrait orientation detection_data[ 'localizerSaliency' ], detection_data[ 'decodedId' ][::-1] # reversed, we want least significant bit last ) ) dset.build_kd_tree() frame_index += 1 # break because we only load the first fname break # loading truth if not os.path.isfile( config.PATHS_FILE ): print 'Error: file not found' return with open( config.PATHS_FILE, 'rb' ) as paths_file: input = pickle.load( paths_file ) if input[ 'source' ] != dset_store.source: print 'Error: data sources do not match' return paths_input = input[ 'paths' ] # match for tag_id in paths_input.keys(): for path_id in paths_input[ tag_id ].keys(): for frame,detection_data in paths_input[ tag_id ][ path_id ].items(): old_detection_id, pos_x, pos_y, readability = detection_data timestamp = dset_store.get_timestamp( frame ) new_detection_id = None distance = None if timestamp is not None and readability < 3: dset = dset_store.get( timestamp ) distances, indices = dset.kd_tree.query( [ pos_x, pos_y ], k=1 ) distance = distances[ 0 ][ 0 ] index = indices[ 0 ][ 0 ] if distance <= MATCH_DISTANCE_LIMIT: new_detection_id = index # use this if you're matching to the same output for test purposes: #if new_detection_id != old_detection_id: # print 'mismatch old: ' + str(old_detection_id) + ', new: ' + str(new_detection_id) paths_input[ tag_id ][ path_id ][ frame ] = ( new_detection_id, pos_x, pos_y, readability ) # saving truth with open( config.PATHS_FILE, 'wb' ) as paths_file: pickle.dump( input, paths_file ) print 'done'