def storeWindowMatches(): myDh = read_JSON.DataHandler() libraries = {'harris': np.load('./library_match_1_segment_harris.npy'), 'histogram': np.load('./library_match_1_segment_histogram.npy')} windowMatches = {} ds = myDh.eventWindowArrayPerActor total = 0 for actor in ds: for data in ds[actor]: total+=1 iter = 0 for actor in ds: windowMatches[actor] = {} for data in ds[actor]: found, frames, scores = findWindow(libraries, data, actor) win_id = data['window'] windowMatches[actor][f'w_{win_id}'] = { 'matched': found, 'frames': list(map(int, frames)), 'scores': list(map(float, scores)) } for e in range(0, len(frames)): windowMatches[actor][f'w_{win_id}'][f'e_{e+1}'] = {} windowMatches[actor][f'w_{win_id}'][f'e_{e+1}']['frame'] = int(frames[e]) windowMatches[actor][f'w_{win_id}'][f'e_{e+1}']['score'] = float(scores[e]) iter += 1 print(f'progress {iter/total:.2f}') with open('stored_json\\player_window_event_matches.txt', 'w') as outfile: json.dump(windowMatches, outfile)
def findEventsInLibrary(): dH = read_JSON.DataHandler() libraries = {} print('Loading libraries...') for ft_name in u.feature_config: print(ft_name) libraries[ft_name] = np.load(u.feature_config[ft_name]['library']) print(libraries[ft_name].shape) print(' loaded _<') for actor in dH.eventWindowArrayPerActor: window_event_features = ['dummy'] win_indx = 1 while len(window_event_features) > 0: window_event_features = glob.glob( f'./resources/event_queries/{actor}_w{win_indx}_e*_harris.npy') if len(window_event_features) == 0: break matched, scores, frames = findWindowInLibrary( libraries, window_event_features) print( f'file: {window_event_features} match: {matched} scores: {scores} ' ) for frame in frames: print(f'frame: {frameOffsetToCommentatorFrame(1,frame)}') video_handler.read_frame( com_path, u.frameOffsetToCommentatorFrame(1, frame), f'{window_event_features[0]} events: {len(window_event_features)}' ) win_indx += 1
def __init__(self): self.com_path = 'C:\save\\2018-03-02_P11.mp4' self.dH = read_JSON.DataHandler() self.guiDs = {} self.libraries = { 'harris': np.load('./library_match_1_segment_harris.npy'), 'histogram': np.load('./library_match_1_segment_histogram.npy') }
def createEventFeatures(): eventData = {} dH = read_JSON.DataHandler() ds = dH.eventWindowArrayPerActor roi = [0.25, 0.55, 0.35, 0.65] for actor in ds: eventData[actor] = {} vid_path = u.playerToPath(actor) window_count = 0 for window in ds[actor]: window_count += 1 eventData[actor][f'w_{window_count}'] = {} event_count = 0 for event_time in window['event_times']: event_count += 1 event_frame = u.event_time_to_stream_frame( event_time, u.player_id[actor], 1) frame = video_handler.get_frame(vid_path, event_frame) frame_roi = ft.get_ROI(frame, roi) harris_result = ft.get_harris_feature(frame_roi) hist_result = ft.extract_frame_histogram(frame_roi) # canny_result = ft.get_canny_feature(frame_roi) harris_filename = f'./resources/event_queries/{actor}_w{window_count}_e{event_count}_harris' hist_filename = f'./resources/event_queries/{actor}_w{window_count}_e{event_count}_histogram' eventData[actor][f'w_{window_count}'][f'e_{event_count}'] = { 'event_frame': event_frame, 'harris_filename': harris_filename, 'hist_filename': hist_filename } np.save(harris_filename, harris_result) np.save(hist_filename, hist_result) # np.save(f'./resources/event_queries/{actor}_w{window_count}_e{event_count}_canny', canny_result) #dump event data json with open('stored_json\\player_event_features.txt', 'w') as outfile: json.dump(eventData, outfile)
def getRankedList(): myDh = read_JSON.DataHandler() ds = myDh.eventWindowArrayPerActor stats = {} for actor in ds: for data in ds[actor]: window_num = data['window'] stored_window_match = u.getWindowStoredData(actor, window_num) if stored_window_match != None: if stored_window_match['matched'] == False: window_stats = {} window_stats['weight'] = data['total_weight'] window_stats['data'] = data window_stats['actor'] = actor stats[f'{actor}_{window_num}'] = window_stats sorted_keys = sorted(stats, key=lambda x: (-1*stats[x]['weight'])) result_dict_list = [] for key in sorted_keys: temp_dict = stats[key] temp_dict['window_name'] = key result_dict_list.append(temp_dict) print(result_dict_list) return result_dict_list
def displayEventsDatasetDemo(display_events=10, show_frames_before=120): myDh = read_JSON.DataHandler() ds = myDh.dataset display_event_count = 0 for event in ds: event_time = event['date'] event_playerid = player_id[event['actor']] event_filename = f"2018-03-02_P{event_playerid}" event_framenumber = utils.event_time_to_stream_frame( event_time, event_playerid, 1) video_path = f'C:\save\\{event_filename}.mp4' vid = read_video(video_path) event_type = event['event_type'] event_actor = event['actor'] display_video(vid, event_framenumber - show_frames_before, title=f'{event_type} {event_actor}') display_event_count += 1 if display_event_count == display_events: break
display_event_count = 0 for event in ds: event_time = event['date'] event_playerid = player_id[event['actor']] event_filename = f"2018-03-02_P{event_playerid}" event_framenumber = utils.event_time_to_stream_frame( event_time, event_playerid, 1) video_path = f'C:\save\\{event_filename}.mp4' vid = read_video(video_path) event_type = event['event_type'] event_actor = event['actor'] display_video(vid, event_framenumber - show_frames_before, title=f'{event_type} {event_actor}') display_event_count += 1 if display_event_count == display_events: break if __name__ == '__main__': myDl = read_JSON.DataHandler() myEventWindows = myDl.eventWindowArrayPerActor """for actor in myDl.actors: print(actor) for i in range(0, len(myDl.eventWindowArrayPerActor[actor])): if myDl.eventWindowArrayPerActor[actor][i]["total_weight"] > 0: print(myDl.eventWindowArrayPerActor[actor][i])"""