def daily_motion_test(db,avaliable_sensor): time_interval = ['2016-12-07 13:00:00', '2016-12-07 14:00:00'] if avaliable_sensor['kinect']: ##get data from database kinect_joints = database.read_kinect_joints_from_db(db.Kinect,time_interval) #extract features from kinect hours = 0 minutes = 0 seconds = 25 time_slice_size = [hours, minutes, seconds] global_traj_features = kinect_global_trajectories.feature_extraction_video_traj(kinect_joints,time_slice_size) #read model from database model= database.get_classifier_model(filename='startPeriod_endPeriod') #test classification classifiers.logistic_regression_predict(global_traj_features[1]) ##visulaization daily motion visualization.bar_plot_occupancy_selectedAreas_over_time(global_traj_features[0]) visualization.bar_plot_motion_over_time(global_traj_features[1]) visualization.pie_plot_motion_day(global_traj_features[1]) if avaliable_sensor['zenith']: print 'add img processing zenith camera' zenith_data = database.read_zenith_from_db(db.Zenith,time_interval) if avaliable_sensor['UPMBand']: print 'add upm band processing' upmBand_data = database.read_UPMBand_from_db(db.UPMBand,time_interval)
def daily_motion_training(db,avaliable_sensor): time_interval = ['2017-07-12 08:03:00', '2017-07-12 08:05:00'] if avaliable_sensor['kinect']: print 'kinect for daily motion' ##get data from database kinect_joints = database.read_kinect_joints_from_db(db.Kinect,time_interval,multithread=0) #extract features from kinect hours = 0 minutes = 0 seconds = 4 date = '2017-07-11' time_slice_size = [hours, minutes, seconds] global_traj_features,patient_ID = kinect_global_trajectories.feature_extraction_video_traj(kinect_joints,time_slice_size, draw_joints_in_scene=1) #Get labels from clustering #labels_cluster = classifiers.cluster_kmeans(global_traj_features[1],k=3) #Train in supervised way a classifier with extracted features and labels #model = classifiers.logistic_regression_train(global_traj_features[1],labels_cluster) #Save model in database #database.save_classifier_model(model,filename='startPeriod_endPeriod') ##visulaization daily motion #visualization.bar_plot_occupancy_selectedAreas_over_time(global_traj_features[0]) #visualization.bar_plot_motion_over_time(global_traj_features[1]) kinect_motion_amount = visualization.pie_plot_motion_day(global_traj_features[1]) ##make it dictionary kinect_motion_amount = {'stationary': kinect_motion_amount[0][0],'slow_mov': kinect_motion_amount[0][1],'fast_mov': kinect_motion_amount[0][2]} if avaliable_sensor['zenith']: print 'add img processing zenith camera' zenith_data = database.read_zenith_from_db(db.Zenith,time_interval) if avaliable_sensor['UPMBand']: print 'add upm band processing' upmBand_data = database.read_UPMBand_from_db(db.UPMBand,time_interval) return kinect_motion_amount,patient_ID
def abnormal_behavior_classification_training(db, avaliable_sensor): ##get data in the selected time interval from database time_interval = ['2016-12-07 13:08:00', '2016-12-07 13:15:00'] if avaliable_sensor['kinect']: print 'kinect disorientation tr' ##get data from database kinect_joints = database.read_kinect_joints_from_db(db.Kinect, time_interval, multithread=0) # extract features from kinect hours = 0 minutes = 0 seconds = 25 time_slice_size = [hours,minutes,seconds] global_traj_features = kinect_global_trajectories.feature_extraction_video_traj(kinect_joints,time_slice_size) ## perform clustering #classifiers.cluster_meanShift(global_traj_features[1],save_model=1) ##retrieve model and get labels #cluster_model = database.get_classifier_model('') ##get labels from clustering #labels_cluster = cluster_model.predict(global_traj_features[1]) ##Create bag of words with trajectories #bow_vocabulary = kinect_global_trajectories.bow_traj(global_traj_features[1],cluster_model,labels_cluster) #classifiers.logistic_regression_train(bow_vocabulary,labels_cluster,save_model=1) if avaliable_sensor['zenith']: zenith_data = database.read_zenith_from_db(db.Zenith,time_interval) if avaliable_sensor['UPMBand']: upmBand_data = database.read_UPMBand_from_db(db.UPMBand,time_interval)
def daily_motion_training(db,avaliable_sensor, time_interval): if avaliable_sensor['kinect']: print 'kinect for daily motion' ##get data from database kinect_joints = database.read_kinect_joints_from_db(db.Kinect,time_interval) #kinect_joints = kinect_joints[::-1] bands_ids = database.get_bands_ID(db) if len(kinect_joints) <1: print '----- no data in time interval -----' kinect_motion_amount_band = {b[0]: None for b in bands_ids} for b in bands_ids: kinect_motion_amount_band[b[0]] = {'stationary': -1,'slow_mov': -1,'fast_mov': -1} return kinect_motion_amount_band #extract HOT features from kinect from each user global_traj_features = kinect_features.feature_extraction_video_traj(kinect_joints, bands_ids, draw_joints_in_scene=0, realtime=0) kinect_motion_amount_band = {b[0]: None for b in bands_ids} ## compute analysis per band for i_b,b in enumerate(bands_ids): if len(global_traj_features[1][i_b])>0: #Get labels from clustering #labels_cluster = classifiers.cluster_kmeans(global_traj_features[1],k=3) #Train in supervised way a classifier with extracted features and labels #model = classifiers.logistic_regression_train(global_traj_features[1],labels_cluster) #Save model in database #database.save_classifier_model(model,filename='startPeriod_endPeriod') ##visulaization daily motion #visualization.bar_plot_occupancy_selectedAreas_over_time(global_traj_features[0]) #visualization.bar_plot_motion_over_time(global_traj_features[1]) kinect_motion_amount = visualization.pie_plot_motion_day(global_traj_features[1][i_b],plot=0) # normalize motion total_motion = np.sum(kinect_motion_amount[0]) for n_k, k_data in enumerate(kinect_motion_amount[0]): kinect_motion_amount[0][n_k] = k_data / total_motion ##make it dictionary kinect_motion_amount_band[b[0]]= {'stationary': kinect_motion_amount[0][0],'slow_mov': kinect_motion_amount[0][1],'fast_mov': kinect_motion_amount[0][2]} print b[0], {'stationary': kinect_motion_amount[0][0],'slow_mov': kinect_motion_amount[0][1],'fast_mov': kinect_motion_amount[0][2]} else: print 'no data from band: ', b[0] kinect_motion_amount_band[b[0]] = {'stationary': -1,'slow_mov': -1,'fast_mov': -1} if avaliable_sensor['zenith']: print 'add img processing zenith camera' zenith_data = database.read_zenith_from_db(db.Zenith,time_interval) if avaliable_sensor['UPMBand']: print 'add upm band processing' upmBand_data = database.read_UPMBand_from_db(db.UPMBand,time_interval) return kinect_motion_amount_band