def main_ui(): #################################### # Basic Info # 처음 시작 UI # Feature # 3가지의 시나리오를 분리합니다. # Todo # Scene no.2, no.3 완성 # Advanced Usage를 위한 경우를 마련해야 합니다. #################################### print(""" ================================================================== CHOOSE WHAT SCENARIO YOU WANT TO USE 1. Register Trainer 2. Get Advice about Exercise Captured from Video 3. Analyze Physical Data and Get Advice from it ------------------------------------------------------------------ FOR DEVELOPERS 4. Initialize DataBase (Init data folder in project root directory) ================================================================== """) main_option = int(input("Enter: ")) if main_option == 1: trainer_ui() elif main_option == 2: diff_videos_ui() elif main_option == 3: physical_ui() elif main_option == 4: DB.initialize()
def __init__(self, user_id): super().__init__() self.setupUi(self) self.show() self.user_id = user_id self.setuserinfo() self.yourlist.clear() self.comboBox.clear() self.comparison.clear() rows = DB.get_input_list(self.user_id) if rows != []: self.input_id_list = rows[:] for row in rows: self.yourlist.addItem(f'{row[0]}.{row[1]}') rows = DB.get_user_list('standard') if rows != []: self.trainer_id_list = list(zip(*rows))[0] for row in rows: self.comboBox.addItem(f'{row[1]}') # 무조건 트레이너 한명은 있다고 가정한다. rows = DB.get_math_info_list(self.trainer_id_list[0]) if rows != None: self.extraction_id_list = rows[:] for row in rows: self.comparison.addItem(f'{row[0]}.{row[1]}') self.extraction_id = 0 self.input_id = 0 self.connectFunction()
def get_feedback(standard_id, exercise_id, input_video_loc): # openpose를 통해서 분석 result_numpy = Method.parse_person(input_video_loc) # 초기자세를 분석 skeleton = Method.find_initial_skeleton(result_numpy) # 초기에 서 있는 자세를 찾을 수 없는 경우 if skeleton == False: print("Error: Couldn't find initial pose. Find another one") return False # Load Math_info extraction info rows = DB.get_math_info(extraction_id) vectors = np.load(rows[0]) # Resizing resized_numpy = Method.resize(exercise_id, skeleton, vectors) # Issue : 운동 분석을 통한 보정 # sample, math_info = Method.analyze_exercise(result_numpy, exercise_id, skeleton) # Issue: 운동 분석을 통한 보정 결과물도 얻을 수 있도록 수정 # if sample_numpy == False: # print("Error: You can't use it") # return False # 파일이름으로 사용할 값 생성 file_name = id_generator() + '.npy' # Issue: Store 구현 return True
def setuserinfo(self): user = DB.get_user_info(self.user_id) if user[0][0] == 'standard': text = f'Hello, Trainer {user[0][1]}' else: text = f'Hello, {user[0][1]}' self.userinfo.setText(text)
def change_extraction_list(self, idx): trainer_id = self.trainer_id_list[idx] self.comparison.clear() rows = DB.get_math_info_list(trainer_id) self.extraction_id_list = rows if rows != None: for row in rows: self.comparison.addItem(f'{row[0]}.{row[1]}')
def __init__(self, user_id): super().__init__() self.setupUi(self) self.show() self.user_id = user_id self.connectFunction() rows = DB.get_input_list(self.user_id) if rows != []: self.input_id_list = rows[:] for row in rows: self.user.addItem(f'{row[0]}.{row[1]}') rows = DB.load_data_list(self.user_id, 2) if rows != []: self.applied_trainer_list = rows[:] for row in rows: self.applied_trainer.addItem(f'{row[0]}.{row[1]}-{row[2]}') self.input_id = 0 self.target_id = 0
def checkUnique(self): is_unique = DB.checkUnique(self.username.text()) if is_unique == False: self.user_unique.setText("Duplicated!") self.user_unique.setStyleSheet('color: red') self.conditions[0] = False else: self.user_unique.setText("Unique!") self.user_unique.setStyleSheet('color: green') self.conditions[0] = True
def __init__(self, user_id): super().__init__() self.setupUi(self) font = QtGui.QFont() font.setFamily("MS Gothic") font.setPointSize(26) self.user_id = user_id self.comboBox.clear() for name in DB.get_exercise_names(): self.comboBox.addItems(name) self.show() self.connectFunction()
def regist_trainer(trainer_id, exercise_id, input_video_loc): # openpose를 통해서 분석 result_numpy = Method.parse_person(input_video_loc) # 초기자세를 분석 skeleton = Method.find_initial_skeleton(result_numpy) # 초기에 서 있는 자세를 찾을 수 없는 경우 if skeleton == False: print("Error: Couldn't find initial pose. Find another one") return False # 보정 및 운동 분석 math_info = Method.analyze_exercise(result_numpy, exercise_id, skeleton) # Issue: 운동 분석을 통한 보정 결과물도 얻을 수 있도록 수정 # if sample_numpy == False: # print("Error: You can't use it") # return False if math_info == False: print("Error: ") # Issue: math_info Extraction 오류 잡기 return False # 파일이름으로 사용할 값 생성 file_name = id_generator() + '.npy' # Store sample_id = DB.save_sample(trainer_id, sample_numpy, file_name, exercise_id) skeleton_id = DB.save_skeleton(trainer_id, skeleton, file_name) math_info_names = [ os.path.split(file_name)[0] + str(i) + os.path.split(file_name)[1] for i in range(len(math_info)) ] extraction_id = DB.save_math_info_extraction(skeleton_id, exercise_id, sample_id, math_info, math_info_names) return True
def __init__(self, user_id): super().__init__() self.setupUi(self) self.show() self.user_id = user_id self.connectFunction() self.setuserinfo() rows = DB.get_input_list(self.user_id) if rows != []: for row in rows: self.yourlist.addItem(f'{row[0]}.{row[1]}') self.input_id_list = rows[:] rows = DB.get_math_info_list(self.user_id) if rows != []: self.extraction_id_list = rows[:] for row in rows: self.registeredlist.addItem(f'{row[0]}.{row[1]}') self.target_type = 0 self.target_id = 0
def physical_ui(): indent = " " * 4 # (exercise_name) # (applied_sample_id, exercise_id, sample_location, user_name, applied_sample_location, trainer_name) exercise_list = DB.get_exercise_names() applied_samples = DB.load_applied_skeleton_list() print(exercise_list) print(""" ================================================================== CHOOSE EXERCISE DATA WHERE YOU WANT TO GET REPORT(USER)""") for idx, row in enumerate(applied_samples): print(indent + "%d. %s: %s by %s" % (idx + 1, exercise_list[row[1] - 1][0], row[3], row[5])) print(indent + """================================================================== """) option = int(input("Enter: ")) args = applied_samples[option] ret_val = PoseSystem.Analyze_Physical_Data(*args) if ret_val == True: print(""" ================================================================== END OF ANALYZE PHYSICAL DATA PROCESS RESULT : SUCCESS ================================================================== """) else: print(""" ================================================================== END OF ANALYZE PHYSICAL DATA PROCESS RESULT : FAIL ================================================================== """) return
def main_function(option, *args): base_folder = 'temp' if os.path.exists(base_folder): shutil.rmtree(base_folder) time.sleep(1) os.mkdir(base_folder) # args = (address_init, address_ex, user_id, exercise_id) if option == 1: # Usage - store blob data into table # file_naming - ./temp/column_name+적절한 확장자 # Store file in temp # insert_input_list(1, 0, "./temp/init_numpy.py", "./temp/init_video.avi", "./temp/exercise_numpy.py", "./temp/exercise_video.avi") # delete temp folder # Usage - read blob data from table # make temp folder # readBlobData(1, 1, 'temp') print(args) input_init = args[0] input_exercise = args[1] output_init_numpy = os.path.join(base_folder, 'init_numpy.npy') output_init_video = os.path.join(base_folder, 'init_video.avi') output_ex_numpy = os.path.join(base_folder, 'exercise_numpy.npy') output_ex_video = os.path.join(base_folder, 'exercise_video.avi') Method.parse_person(input_init, output_init_numpy, output_init_video) Method.parse_person(input_exercise, output_ex_numpy, output_ex_video) DB.insert_input_list(args[2], args[3], output_init_numpy, output_init_video, output_ex_numpy, output_ex_video) elif option == 2: DB.read_from_input_list(args[0], base_folder) numpy = np.load(os.path.join(base_folder, 'init_numpy.npy')) skeleton_numpy = 'skeleon.npy' graph_numpy = 'graph.npy' (res1, res2) = Method.find_initial_skeleton(numpy, base_folder, args[1]) # print(res1, res2) np.save(os.path.join(base_folder, skeleton_numpy), [res1, res2]) pk = DB.save_skeleton(args[0], os.path.join(base_folder, skeleton_numpy), os.path.join(base_folder, graph_numpy)) return (res1, res2, pk) elif option == 3: DB.read_from_input_list(args[1], base_folder) numpy = np.load(os.path.join(base_folder, 'exercise_numpy.npy')) (res1, res2) = Method.find_initial_skeleton(numpy, base_folder) DB.load_skeleton(args[0], base_folder) ex_type = 2 time.sleep(0.5) numpy_array = np.load(os.path.join(base_folder, 'exercise_numpy.npy')) skeleton = np.load(os.path.join(base_folder, 'skeleton.npy'))[0] target_skeleton = skeleton common = bc_common.Common() accuracy, body_part = common.check_accuracy(numpy_array, ex_type, 0) input_vector = common.calculate_trainer(ex_type, skeleton, body_part[0], body_part[1]) resized = common.apply_vector(ex_type, target_skeleton, input_vector) np.save(os.path.join(base_folder, 'math_info.npy'), input_vector) np.save(os.path.join(base_folder, 'resized.npy'), resized) screen = run.human_pic(resized, os.path.join(base_folder, 'math_info.avi')) DB.save_math_info_extraction( args[0], os.path.join(base_folder, 'math_info.npy'), os.path.join(base_folder, 'math_info.avi')) elif option == 4: exercise_id = DB.get_exercise_id(args[2])[0][0] DB.load_skeleton(args[0], base_folder) DB.load_math_info_extraction(args[1], base_folder) ex_type = 2 time.sleep(0.5) math_info = np.load(os.path.join(base_folder, 'math_info.npy')) skeleton = np.load(os.path.join(base_folder, 'skeleton.npy'))[0] common = bc_common.Common() resized = common.apply_vector(ex_type, skeleton, math_info) (res1, res2) = Method.find_initial_skeleton(resized, base_folder) np.save(os.path.join(base_folder, 'resized.npy'), resized) screen = run.human_pic(resized, os.path.join(base_folder, 'resized.avi')) DB.save_applied_sample(args[0], args[1], exercise_id, os.path.join(base_folder, 'resized.npy'), os.path.join(base_folder, 'resized.avi')) elif option == 5: pass # args = (input_id, sample_id) elif option == 6: video_name = os.path.join(base_folder, 'output.avi') numpy_name = os.path.join(base_folder, 'graph.npy') DB.load_applied_skeleton_file(args[1], base_folder) DB.read_from_input_list(args[0], base_folder) input1 = os.path.join(base_folder, 'upgraded.npy') input2 = os.path.join(base_folder, 'exercise_numpy.npy') run.Video(input1, input2, video_name) DB.save_diff(args[1], args[0], video_name, numpy_name) elif option == 7: input2 = 'data/result.avi' input1 = 'data/user/exercise/raw/output_video/result.avi' selected = 'user' file_names = [ 'data/%s/exercise/exercise_left_elbow.npy' % (selected, ), 'data/%s/exercise/exercise_right_elbow.npy' % (selected, ), 'data/%s/exercise/exercise_left_knee.npy' % (selected, ), 'data/%s/exercise/exercise_right_knee.npy' % (selected, ) ] plot_titles = [ 'left_elbow angle', "right_elbow angle", "left_knee angle", "right_knee angle" ] get_result.debugger(0, isImage=False, video=input1, video2=input2, file_name=file_names, plot_title=plot_titles, title1='pose difference algorithm', title='original user exercise', title2='graph data for main angle') elif option == 8: # DB.load_applied_skeleton_file(args[1], base_folder) # DB.read_from_input_list(args[0], base_folder) # input1 = np.load(os.path.join(base_folder, 'upgraded.npy')) # input2 = np.load(os.path.join(base_folder, 'exercise_numpy.npy')) user_info = DB.get_user_info_full(args[0]) other_info = DB.get_diff_info(args[2]) DB.load_skeleton(args[1], base_folder) DB.load_diff(args[2], base_folder) input = os.path.join(base_folder, 'graph.npy') input2 = np.load(os.path.join(base_folder, 'skeleton.npy'))[0] input3 = os.path.join(base_folder, 'skeleton.png') info = user_info[0] + other_info[0] run.make_skeleton_image(input2, input3, 2) report.make_graph(input, base_folder) paragraph = report.make_paragraph(input) report.insert_image_and_pictures(info, paragraph) elif option == 10: PoseDifference.main_ui()
def change_ucs(self, i): self.ids.clear() self.data = [] for row in DB.load_data_list(self.user_id, i): self.ids.addItem(str(row[0]) + "-" + row[1]) self.data.append(row)
def loading(self): if self.cpt != None or self.cpt2 != None: self.cpt.release() self.cpt2.release() self.play = False index = self.ucs.currentIndex() datas = self.data[self.ids.currentIndex()] self.graph_title = self.graph_titles[index] base_folder = 'temp' if os.path.exists(base_folder): shutil.rmtree(base_folder) time.sleep(1) os.mkdir(base_folder) if index == 0: # file load DB.read_from_input_list(datas[2], base_folder) DB.load_skeleton(datas[0], base_folder) # video self.origin_file = 'temp/init_video.avi' self.copy_file = 'temp/init_video.avi' elif index == 1: # file load DB.load_skeleton(datas[3], base_folder) # N DB.load_math_info_extraction(datas[2], base_folder) DB.load_applied_skeleton_file(datas[0], base_folder) # video self.origin_file = 'temp/math_info.avi' self.copy_file = 'temp/upgraded.avi' elif index == 2: # file load DB.read_from_input_list(datas[2], base_folder) DB.load_diff(datas[0], base_folder) # video self.origin_file = 'temp/exercise_video.avi' self.copy_file = 'temp/diff.avi' elif index == 3: # file load DB.load_skeleton(datas[3], base_folder) # N DB.read_from_input_list(datas[2], base_folder) DB.load_math_info_extraction(datas[0], base_folder) # video self.origin_file = 'temp/exercise_video.avi' self.copy_file = 'temp/math_info.avi' self.graph() self.Video()
def diff_videos_ui(): #################################### # Basic Info # Scene No.2 유저가 비디오 분석을 받기 위한 UI이다. # Console Based UI가 기본이고 INPUT에 대한 exception을 처리한다. # Feature # 유저로부터 Input을 받고 적절한 함수를 호출합니다. # Todo # 결과창 띄우기 (A+) # 비디오 분석 건너 뛰기 옵션 적용 (A) # Video 조건 영어로 번역 #################################### # For Print Format indent = " " * 4 # Get the number of math_info for exercise exercise_list = DB.get_exercise_list() for idx, exercise in enumerate(exercise_list): exercise_list[idx] = list(exercise) + [ len(DB.get_math_info_list_per_exercise(exercise[0])) ] # Select Exercise print(""" ================================================================== CHOOSE WHICH EXERCISE YOU WANT TO GET ADVICE FOR""") for idx, row in enumerate(exercise_list): print(indent + "%d. %s [%d]" % (idx + 1, row[1], row[2])) print(indent + """================================================================== """) option = int(input("Enter: ")) if exercise_list[option - 1][2] == 0: print(""" ================================================================== END OF GET ADVICE PROCESS RESULT : FAIL ERROR : Select Exercise Which Trainer Registered Before ================================================================== """) return exercise_id = exercise_list[option - 1][0] # Select Math Info rows = DB.get_math_info_list_per_exercise(exercise_id) print(""" ================================================================== CHOOSE TRAINER WHO YOU WANT TO GET ADVICE FROM""") for idx, row in enumerate(rows): print(indent + "%d. %s: %s" % (idx + 1, row[3], row[2])) print(indent + """================================================================== """) option = int(input("Enter: ")) standard_id = rows[option - 1][0] print(""" ================================================================== ENTER LOCATION OF INPUT VIDEO FILE (PLEASE CHECK VIDEO CONDITION) 1. Stand Upright Still at Least 1 Sec 2. 카메라로부터 운동하는 사람과의 거리는 해당 사람이 똑바로 서있을때와 동일해야 합니다. 3. The Maximum number of people in Video is 1 4. Cam should not Move ================================================================== """) input_video_loc = input("Enter (relative path): ") ret_val = False try: if os.path.exists(input_video_loc): ret_val = PoseSystem.get_feedback(standard_id, exercise_id, input_video_loc) else: raise Exception() except Exception: traceback.print_exc() return if ret_val == True: print(""" ================================================================== END OF GET ADVICE PROCESS RESULT : SUCCESS ================================================================== """) else: print(""" ================================================================== END OF GET ADVICE PROCESS RESULT : FAIL ================================================================== """) return
def trainer_ui(): #################################### # Basic Info # Scene No.1 트레이너 등록을 위한 UI 이다. # Console Based UI가 기본이고 INPUT에 대한 exception을 처리한다. # Feature # 유저로부터 Input을 받고 적절한 함수를 호출합니다. # Todo # 결과창 띄우기 (A+) # 비디오 분석을 건너뛰고 등록된 sample을 이용할 수 있는 옵션 추가(A) # Exercise 추가 기능 (B) # Video 조건 영어로 번역 (A) #################################### # For Print Format indent = " " * 4 # Select Exercise rows = DB.get_user_list('standard') rows.append([]) print(""" ================================================================== CHOOSE WHICH TRAINER YOU WANT TO REGISTER EXERCISE FOR""") for idx, row in enumerate(rows): if idx != len(rows) - 1: print(indent + "%d. %s" % (idx + 1, row[1])) else: print(indent + "%d. Register New Trainer" % (idx + 1, )) print(indent + """================================================================== """) option = int(input("Enter: ")) # Get PK for table of user_list trainer_id = 0 if option == len(rows): print(""" ================================================================== Register New Trainer 1. Name (English) 2. Weight (kg) 3. Stature (cm) 4. Other Info 5. Sex (men or women) ================================================================== """) # Regist New Trainer register_form = ['standard'] try: register_form.append(input("Enter Name: ")) register_form.append(int(input("Enter Weight(kg): "))) register_form.append(int(input("Enter Height(cm): "))) register_form.append(input("Enter Other Info: ")) register_form.append(input("Enter Sex: ")) if register_form[5] not in ('men', 'women', ''): raise Exception() except ValueError: print('Please enter an integer') return except Exception: print("Please enter men or women for your sex") return trainer_id = DB.create_user(*register_form) else: trainer_id = rows[option - 1][0] # Get the number of Exercise for trainer exercise_list = DB.get_exercise_list() for idx, exercise in enumerate(exercise_list): exercise_list[idx] = list(exercise) + [ len( DB.get_registered_exercise_for_one_user( trainer_id, exercise[0])) ] # Select Exercise Type print(""" ================================================================== CHOOSE WHICH EXERCISE YOU WANT TO REGISTER EXERCISE FOR""") for idx, row in enumerate(exercise_list): print(indent + "%d. %s [%d]" % (idx + 1, row[1], row[2])) print(indent + """================================================================== """) option = int(input("Enter: ")) exercise_id = exercise_list[option - 1][0] print(""" ================================================================== ENTER LOCATION OF INPUT VIDEO FILE (PLEASE CHECK VIDEO CONDITION) 1. Stand Upright Still at Least 1 Sec 2. 카메라로부터 운동하는 사람과의 거리는 해당 사람이 똑바로 서있을때와 동일해야 합니다. 3. The Maximum number of people in Video is 1 4. Cam should not Move ================================================================== """) input_video_loc = input("Enter (relative path): ") ret_val = False try: if os.path.exists(input_video_loc): ret_val = PoseSystem.regist_trainer(trainer_id, exercise_id, input_video_loc) else: raise Exception() except Exception: traceback.print_exc() return if ret_val == True: print(""" ================================================================== END OF TRAINER REGISTER PROCESS RESULT : SUCCESS ================================================================== """) else: print(""" ================================================================== END OF TRAINER REGISTER PROCESS RESULT : FAIL ================================================================== """) return