---
tags: openpose
---
# 解析 start_here.py
## 2021/6/8
### https://github.com/kr1210/Human-Pose-Compare
[Python argparse 教學:比 sys.argv 更好用,讓命令列引數整潔又有序](https://haosquare.com/python-argparse/)

```
print(args)
```
> {'activity': 'punch - side', 'video': 'test.mp4', 'lookup': 'lookup_test.pickle'}

```
class get_Score(object):
def __init__(self, lookup='lookup.pickle'):
self.a = Pose()
self.s = Score()
self.b = pickle.load(open(lookup, 'rb'))
self.input_test = []
def get_action_coords_from_dict(self,action):
for (k,v) in self.b.items():
if k==action:
(model_array,no_of_frames) = (v,v.shape[0])
return model_array,no_of_frames
def calculate_Score(self,video,action):
with tf.Session() as sess:
model_cfg, model_outputs = posenet.load_model(101, sess)
model_array,j = self.get_action_coords_from_dict(action)
cap = cv2.VideoCapture(video)
i = 0
if cap.isOpened() is False:
print("error in opening video")
while cap.isOpened():
ret_val, image = cap.read()
if ret_val:
input_points= self.a.getpoints(cv2.resize(image,(372,495)),sess,model_cfg,model_outputs)
input_new_coords = np.asarray(self.a.roi(input_points)[0:34]).reshape(17,2)
self.input_test.append(input_new_coords)
i = i + 1
else:
break
cap.release()
final_score,score_list = self.s.compare(np.asarray(self.input_test),np.asarray(model_array),j,i)
return final_score,score_list
```
----

```
self.input_test.append(input_new_coords)
```
```
print(input_test)
```
>
> [[[5.15185883e+01 8.93372718e+00]
> [4.70564352e+01 2.76518550e-01]
> [4.32060295e+01 2.80458725e+00]
> ...
> [4.81518769e+00 1.71306666e+02]
> [5.91169274e+01 2.00305826e+02]
> [9.84054851e+00 2.16749087e+02]]
>
> [[5.13339807e+01 9.12596124e+00]
> [4.68509959e+01 5.62279158e-01]
> [4.30994279e+01 3.15361881e+00]
> ...
> [4.78943200e+00 1.71618791e+02]
> [5.88837917e+01 2.00361205e+02]
> [9.67429361e+00 2.16373234e+02]]
>
> [[5.12240261e+01 8.31889213e+00]
> [4.71536351e+01 1.85923245e-01]
> [4.13419523e+01 8.99014063e-01]
> ...
> [4.89588128e+00 1.70029727e+02]
> [5.92805614e+01 1.99135659e+02]
> [9.97858550e+00 2.14544162e+02]]
>
> ...
>
> [[6.73014211e+01 6.55544648e+00]
> [6.78065007e+01 4.08304853e-02]
> [5.71713807e+01 4.76013846e-02]
> ...
> [1.72097225e+01 1.70479383e+02]
> [5.83745494e+01 2.09495166e+02]
> [7.10029574e+00 2.25326491e+02]]
>
> [[6.60858784e+01 1.04955383e+01]
> [6.86857932e+01 7.63566434e-01]
> [5.79223253e+01 8.23889169e-01]
> ...
> [1.83621662e+01 1.70635853e+02]
> [6.02386019e+01 2.12411212e+02]
> [5.32813609e+00 2.25000675e+02]]
>
> [[6.67499721e+01 8.56490846e+00]
> [6.96779475e+01 1.13766083e+00]
> [5.75924724e+01 6.73452330e-01]
> ...
> [1.75765766e+01 1.69598580e+02]
> [5.78942389e+01 2.11459764e+02]
> [1.88587547e+00 2.23324988e+02]]]
```
for k in range(0,17):
print(input_test[:,0])
```
>
> [[51.51858831 8.93372718]
> [51.33398072 9.12596124]
> [51.22402607 8.31889213]
> [51.33176559 9.01373744]
> [49.99546138 6.78830115]
> [50.67814301 8.18894268]
> [51.14128007 9.4083843 ]
> [51.89035896 9.81396628]
> [50.07277233 9.22365009]
> [50.32534902 8.03248702]
> [50.81750197 8.24566023]
> [51.01097392 8.09056355]
> [49.29549235 7.3279541 ]
> [47.17383286 7.38705819]
> [46.06379066 8.20491374]
> [46.4909112 5.02173387]
> [46.87247976 7.8973302 ]
> [46.97264443 8.27593084]
> [46.80982905 7.66563908]
> [48.62710106 6.85264315]
> [47.48031604 5.34719654]
> [48.79323193 5.08359244]
> [51.65116105 7.65676647]
> [51.39405506 3.51596849]
> [54.33096524 5.73982174]
> [54.50814317 6.55525039]
> [54.55890175 8.1255707 ]
> [55.35843206 10.46874612]
> [57.51757888 7.83458139]
> [60.84092025 8.68122924]
> [71.40756873 9.38493806]
> [76.6397007 10.44422724]
> [80.58548938 10.38817717]
> [83.59579254 10.82216001]
> [87.69912298 11.04314905]
> [88.140408 8.01138462]
> [92.02880019 7.97607667]
> [88.12723067 8.72681921]
> [80.40655837 11.04218283]
> [81.92215335 11.08065349]
> [83.21772101 11.09518771]
> [84.74804541 10.88903498]
> [83.23441816 10.565317 ]
> [83.34035428 10.29304636]
> [82.0554664 10.92209667]
> [81.58297802 10.02107389]
> [80.99297385 11.20039526]
> [75.95746712 10.1605082 ]
> [75.18788673 9.32393459]
> [74.84043395 9.58139443]
> [75.11842045 10.56339222]
> [71.93977778 8.89534011]
> [73.18177202 9.35506008]
> [69.35248072 9.39511139]
> [68.21253096 9.40227896]
> [66.5384987 9.21346487]
> [66.96207155 7.3176107 ]
> [61.10535719 7.64625031]
> [57.85705763 7.74502609]
> [58.20102909 9.45068532]
> [58.16386743 9.5869242 ]
> [56.93216549 9.14349526]
> [56.51814807 8.33990715]
> [55.13838746 4.70463958]
> [51.90544888 5.26264206]
> [50.56485227 7.04251829]
> [49.09886818 8.24641716]
> [46.98728197 8.64247968]
> [47.02653441 8.80683298]
> [46.92318308 8.70287038]
> [46.12964632 8.50447636]
> [45.9800049 9.07556261]
> [44.45339678 8.75332438]
> [45.32177251 8.647593 ]
> [45.61745049 9.09427852]
> [45.45821041 8.64856364]
> [45.27162204 8.626186 ]
> [44.3687683 8.2058772 ]
> [45.24456842 7.92421653]
> [47.10428434 7.769096 ]
> [48.10212354 8.12740013]
> [46.93033107 7.24402184]
> [49.99529043 7.5000429 ]
> [51.75689434 6.34980884]
> [52.08613648 6.55359681]
> [53.56658045 6.49161104]
> [53.30971989 6.88087229]
> [55.16485413 7.41615688]
> [54.13196247 7.37677851]
> [54.54908656 7.19299967]
> [61.89855259 7.60462579]
> [64.68014612 7.58514172]
> [66.76030072 7.90510166]
> [68.416573 6.75983989]
> [66.99056076 6.92570219]
> [67.30142113 6.55544648]
> [66.0858784 10.49553829]
> [66.74997215 8.56490846]]
### input_test[:,k]/np.linalg.norm(input_test[:,k])
----
### 參考資料:
[Python 字典(Dictionary) items()方法](https://www.runoob.com/python/att-dictionary-items.html)
[[Python+OpenCV] 圖片縮放 resize](https://shengyu7697.github.io/python-opencv-resize/)