-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_image.py
42 lines (29 loc) · 1.04 KB
/
main_image.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
from model import Net
from detect import hand_detect
import torch
import cv2
import skeleton
import os
import midi
if __name__ == "__main__":
model=Net().to('cuda') #모델 할당
model.load_state_dict(torch.load('model/Net.pth')) # 학습된 모델 로드
hand = skeleton.hand()
music = midi.midi()
path='./test/true/'
image_list=[path+x for x in os.listdir(path)]
for image_path in image_list:
image =cv2.imread(image_path)
catch_flag = hand.detection(image)
leftX, leftY = hand.get_left_center()
rightX, rightY = hand.get_right_center()
distanceX, distanceY = hand.get_distance()
points=torch.FloatTensor(hand.points).view(1,-1).to('cuda')
hand_state=hand_detect(model,points)
hand_sign = hand_state
melody = music.to_note(distanceX, distanceY)
if melody == -1:
continue
music.sound(hand_sign, melody)
print(distanceX,distanceY)
print('melody =',melody)