-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_main.py
141 lines (125 loc) · 6.4 KB
/
function_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from pose_diff.util import Method, screen, bc_common
from pose_diff.interface import Screen, PoseDifference
from pose_diff.interface import get_result
from pose_diff.core.save_docx import save_docx
from pose_diff.core import report
from pose_diff.DB import DB
import argparse
import numpy as np
import os
from pose_diff.core import run
import cv2
import shutil
import time
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()