-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_thread.py
83 lines (59 loc) · 2.22 KB
/
render_thread.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
'''
##### DO Not Touch your face ver.0.2
### Medical Imaging & Intelligent Reality Lab (MI2RL) @ Asan Medical Center(AMC)
# MI2RL website : https://www.mi2rl.co/
# AMC : http://www.amc.seoul.kr/asan/main.do
### Developer
# Sungman Cho : dev.sungman@gmail.com
# Minjee Kim : minjeekim00@gmail.com
# Taehyeong Kim : kimtaehyeong62@gmail.com
# Junmyung Choi : jm5901@gmail.com
# Namkug Kim : namkugkim@gmail.com
### Data contributor
# MI2RL researchers
# Dongwoo Seo, Emergency Medicine@AMC
# Namkug Kim, Convergence Medicine@AMC
### references
# I3D Network (https://github.com/hassony2/kinetics_i3d_pytorch)
#####
'''
import cv2
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
#from action_classifier import ActionClassifier
from action_classifier_mobile import ActionClassifier
import time
class RenderThread(QThread):
status = None
exitFlag = False
#action_classifier = ActionClassifier(model_path='weights/i3d_rgb_multi_class_new.pth')
#action_classifier = ActionClassifier(model_path='weights/i3d_rgb_multi_class.pth')
action_classifier = ActionClassifier(model_path='weights/mobilenet_v3-173-best.pth')
changePixmap = pyqtSignal(QImage)
action_result = pyqtSignal(str)
def run(self):
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if ret:
rgb_img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
rgb_img = cv2.resize(rgb_img, (480,320))
h, w, ch = rgb_img.shape
if self.status is False:
result = self.action_classifier.run(rgb_img)
self.action_result.emit(result)
bytesPerLine = ch * w
convertToQtFormat = QImage(rgb_img.data, w, h, bytesPerLine, QImage.Format_RGB888)
p = convertToQtFormat.scaled(480,320, Qt.KeepAspectRatio)
self.changePixmap.emit(p)
if self.exitFlag is True:
break
def setStatus(self, status):
self.status = status
def get_action_result(self):
return self.action_result
def exit(self, bool_flag):
self.exitFlag = True