def analyzing(): # get upload video in_vlist = session.get("upload_video") # Perform video tracking and write information to database # clear the graph K.clear_session() # perform video_tracking det_list, logfile, tracking_list = video_tracking(in_vlist, download_dir, td_dir, log_dir) # assign det_list to out_vlist for downloading out_vlist = [os.path.basename(f) for f in det_list] # write log data to database log = configparser.ConfigParser() log.read(logfile) log_section = log.sections() for section in log_section: log_data = dict(log.items(section)) db.upsert_data(table_name="log", **log_data) # Save video's heat_map to database for in_video in in_vlist: # create heat map for the video heatmap_path = create_heatmap(in_video, heatmap_dir) # read heatmap file as binary heatmap_binary = open(heatmap_path, "rb").read() # prepare data to write to overlay table heatmap_data = { "video_name": os.path.basename(in_video), "file_extension": "jpg", "heatmap_binary": psycopg2.Binary(heatmap_binary) } # write heat map data to database db.upsert_data("heatmap", **heatmap_data) # save pedestrian' activity data to database for video_path, tracking_path in zip(in_vlist, tracking_list): num_pedestrians, pedestrian_info = activity_analyzing(tracking_path) video_name = "_".join(os.path.basename(video_path).split(".")) db.create_table(table_name=video_name) for person in pedestrian_info: print(person) db.upsert_data(table_name=video_name, condition="person_id", **person) return render_template("result.html", list=out_vlist)
def update_heatmap(title, hm_click): #optional space for creating e.g. RESET button return create_heatmap(title, hm_click)
machine_learning_table = ColumnDataSource(data=dict()) ML_table = DataTable(source=machine_learning_table, columns=churn_table_columns, row_headers=False, editable=True, width=280, height=160) ############################################################################## # Create heatmap ########################## from heatmap import create_heatmap hm = create_heatmap(customer_directory_df) ############################################################################## # Linear regression plot ################################ import numpy as np from bokeh.plotting import * from bokeh.models import ColumnDataSource, DatetimeTickFormatter, NumeralTickFormatter, PrintfTickFormatter from math import pi from bokeh.models.glyphs import Line # TODO: put this in maprdb and query it with Drill DATA_FILE = "/home/mapr/customer360/bokeh/datasets/credit_card_transactions.csv" txndf = pd.read_csv(DATA_FILE, thousands=',') txndf['Date'] = pd.to_datetime(txndf['Date'], format='%m/%d/%Y')
def detect_referee(hg_matrix): global referee_position global input_ball global flag #İlk açılan pencereler win_Settings(0) #Hakem rengi belirlemek için low_color = np.array([35, 0, 150]) high_color = np.array([85, 170, 255]) #Daha önce oluşturulan saha içi maske area_mask = cv2.imread(field_mask_path) cap = cv2.VideoCapture(vid_filepath) #Hakemin ilk konumunu belirlemek ve konum bulmak için pencere boyutları resize_x = 40 resize_y = 30 frame = set_object_pos(cap) frame = init_frames(frame, resize_x, resize_y) x = 0 y = 0 w = 0 h = 0 #Top_view'e konum atmak için arraylar input_pts = [] input_referee = [[0, 0], 'r'] input_ball = [[0, 0], 'null'] feet_coord = [0, 0] #Top_View boyutlarında ısı haritası oluşturma heatmap.create_heatmap() heat_key = True mask_key = False #-Hakemin her iki saniyedeki hızı print('Starting..\n\n') print( 'Click anywhere on Main_Frame to determine the distance.\n L-Mouse: Choose point\n R-Mouse: Remove point' ) second = 2 rt = speed.RepeatedTimer(second, speed.flag) #----- Hakemin tespit edilip işaretlendiği kısım --------- while True: ret, frame = cap.read() if ret: area_masked = cv2.bitwise_and(frame, area_mask) cropped_frame_referee = area_masked[resized_r[0]:resized_r[1], resized_r[2]:resized_r[3]] #Maskeleme işlemleri masked = image_masks(cropped_frame_referee, low_color, high_color) image, contours, hierarchy = cv2.findContours( masked, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) if (len(contours) <= 0): cv2.rectangle(cropped_frame_referee, (x, y), (x + w, y + h), (0, 0, 255), 2) cv2.rectangle(frame, (x + resized_r[2], y + resized_r[0]), (x + w + resized_r[2], y + h + resized_r[0]), (0, 255, 0), 2) else: for contour in contours: (x, y, w, h) = cv2.boundingRect(contour) if ((w < 22 or h < 20) or (w > 40 or h > 45)): continue feet_coord = [ float((x + resized_r[2]) + int(25 / 2.0)), float((y + resized_r[0]) + 25) ] # feet_coord = [x + w/2, y + h)] input_referee = [feet_coord, 'r'] cv2.rectangle(cropped_frame_referee, (x, y), (x + w, y + h), (0, 0, 255), 2) cv2.rectangle(frame, (x + resized_r[2], y + resized_r[0]), (x + w + resized_r[2], y + h + resized_r[0]), (0, 255, 0), 2) if (x != 0 and y <= 5): set_resized_r(0, frame_lenx) if (y >= resize_x * 2 - h - 5): set_resized_r(1, frame_lenx) if (x <= 5 and y != 0): set_resized_r(2, frame_lenx) if (x >= resize_y * 2 - w - 5): set_resized_r(3, frame_lenx) cv2.setMouseCallback('Main_Frame', on_mouse_click, [x + resized_r[2], y + resized_r[0]]) input_pts = [input_referee, input_ball] top_img, player_top_points = top_view.create_topview( hg_matrix, input_pts) heatmap_mask = heatmap.add(player_top_points[0][0]) ref_speed = speed.cal_speed(time.localtime().tm_sec, player_top_points[0][0]) top_img = drawoffside.drawspeed(top_img, player_top_points, ref_speed) if (player_top_points[1][1][0] == 'b'): rb_distance = distance.cal_distance(player_top_points) top_img = drawoffside.drawLine(top_img, player_top_points, rb_distance) cv2.imshow('Main_Frame', frame) cv2.imshow('Top_View', top_img) #Gereksiz kalabalık m tuşuna basınca gözükmesi ve kapanması için if mask_key: win_Settings(1) cv2.imshow('Mask_Frame', masked) cv2.imshow('Cropped_Frame', cropped_frame_referee) else: cv2.destroyWindow('Mask_Frame') cv2.destroyWindow('Cropped_Frame') else: print("ret, false, video bitti") win_Settings(2) colored_heatmap = heatmap.colorize(heatmap_mask) cv2.imshow('Heat_Map_Mask', heatmap_mask) cv2.imshow('Heat_Map_Color', colored_heatmap) #Tuş takımı key = cv2.waitKey(15) & 0xFF if key == ord('h'): if heat_key: win_Settings(2) colored_heatmap = heatmap.colorize(heatmap_mask) cv2.imshow('Heat_Map_Mask', heatmap_mask) cv2.imshow('Heat_Map_Color', colored_heatmap) heat_key = False else: heat_key = True cv2.destroyWindow('Heat_Map_Mask') cv2.destroyWindow('Heat_Map_Color') if key == ord('m'): if mask_key: mask_key = False else: mask_key = True if key == ord('q'): break rt.stop() cap.release() cv2.destroyAllWindows()