22from  PyQt5 .QtGui  import  QImage , QPixmap 
33
44import  MainWindow 
5- from  inputs .BlinkDetector  import  BlinkDetector 
65from  inputs .FaceDetector  import  FaceDetector 
76from  inputs .GazeDetectorCnn  import  GazeDetector 
87from  inputs .Speech  import  Speech 
1918class  Controller :
2019    def  __init__ (self , main_window , giveOutput ):
2120        self .gazeImg  =  None 
22-         self .blink_detector  =  BlinkDetector ()
2321        self .face_detector  =  FaceDetector ()
2422        self .gaze_detector  =  GazeDetector ()
2523        # self.speech_detector = Speech() 
@@ -28,91 +26,100 @@ def __init__(self, main_window, giveOutput):
2826        self .cap  =  cv2 .VideoCapture (0 )
2927
3028    def  getInput (self ):
31-         dicBlink  =  None 
32-         dicGaze  =  None 
33-         dicHead  =  None 
3429        label  =  "" 
35-         self .drawImg  =  None 
36-         img  =  None 
3730
3831        # Blink 
39-         if  True :
40-             _ , img  =  self .cap .read ()
41-             dicBlink  =  self .blink_detector .processImage (img , self .main_window .eyeThreshold .value ())
42- 
43-             drawImg  =  dicBlink ["img" ]
44- 
45-             label  =  label  +  \
46-                     "Blink Detector : "  +  "\n "  \
47-                                           "\t "  +  "both : "  +  str (dicBlink ["both" ]) +  "\n "  \
48-                                                                                      "\t "  +  "left : "  +  str (
49-                 dicBlink ["left" ]) +  "\n "  \
50-                                     "\t "  +  "right : "  +  str (dicBlink ["right" ]) +  "\n "  \
51-                                                                                  "\t "  +  "leftEAR : "  +  str (
52-                 dicBlink ["leftEAR" ]) +  "\n "  \
53-                                        "\t "  +  "rightEAR :"  +  str (dicBlink ["rightEAR" ]) +  "\n "  \
54-                                                                                          "\t "  +  "bothTotal : "  +  str (
55-                 dicBlink ["bothTotal" ]) +  "\n "  \
56-                                          "\t "  +  "leftTotal : "  +  str (dicBlink ["leftTotal" ]) +  "\n "  \
57-                                                                                               "\t "  +  "rightTotal : "  +  str (
58-                 dicBlink ["rightTotal" ]) +  "\n "  \
59-  \
60-                 # Head 
61-         if  self .main_window .selectMethodComboBox .currentIndex () ==  MainWindow .METHOD .HEAD_HELP :
62-             dicHead  =  self .face_detector .processImage (img , drawImg )
63- 
64-             label  =  label  +  \
65-                     "Head Detector : "  +  "\n "  \
66-                                          "\t "  +  "direction : "  +  str (dicHead ["direction" ]) +  "\n " 
67- 
68-         # GAZE 
69-         if  self .main_window .selectMethodComboBox .currentIndex () ==  MainWindow .METHOD .EYE_HELP  \
70-                 and  self .main_window .current_mode  in  [MainWindow .MODE .CHAIR , MainWindow .MODE .KEYBOARD ]:
71- 
72-             dicGaze  =  self .gaze_detector .processImage (img )
73- 
74-             label  =  label  +  \
75-                     "Gaze Detector : "  +  "\n "  \
76-                                          "\t "  +  "Gaze : "  +  str (dicGaze ["direction" ]) +  "\n " 
77- 
78-             if  dicGaze ["img" ] is  not None :
79-                 self .gazeImg  =  dicGaze ["img" ]
80-                 self .gazeImg  =  toQImage (self .gazeImg )
81-                 self .gazeImg  =  self .gazeImg .rgbSwapped ()
82- 
83-             if  self .gazeImg  is  not None :
84-                 self .main_window .gaze_image_label .setPixmap (QPixmap .fromImage (self .gazeImg ))
85-             else :
86-                 self .main_window .gaze_image_label .setText ("None" )
87- 
88-         outImage  =  toQImage (drawImg )
32+  #        if True: 
33+  #            _, img = self.cap.read() 
34+  #            dicBlink = self.blink_detector.processImage(img, self.main_window.eyeThreshold.value()) 
35+  # 
36+  #            drawImg = dicBlink["img"] 
37+  # 
38+  #            label = label + \ 
39+  #                    "Blink Detector : " + "\n" \ 
40+  #                                          "\t" + "both : " + str(dicBlink["both"]) + "\n" \ 
41+  #                                                                                     "\t" + "left : " + str( 
42+  #                dicBlink["left"]) + "\n" \ 
43+  #                                    "\t" + "right : " + str(dicBlink["right"]) + "\n" \ 
44+  #                                                                                 "\t" + "leftEAR : " + str( 
45+  #                dicBlink["leftEAR"]) + "\n" \ 
46+  #                                       "\t" + "rightEAR :" + str(dicBlink["rightEAR"]) + "\n" \ 
47+  #                                                                                         "\t" + "bothTotal : " + str( 
48+  #                dicBlink["bothTotal"]) + "\n" \ 
49+  #                                         "\t" + "leftTotal : " + str(dicBlink["leftTotal"]) + "\n" \ 
50+  #                                                                                              "\t" + "rightTotal : " + str( 
51+  #                dicBlink["rightTotal"]) + "\n" \ 
52+  # \ 
53+  #                # Head 
54+  #        if self.main_window.selectMethodComboBox.currentIndex() == MainWindow.METHOD.HEAD_HELP: 
55+  #            dicHead = self.face_detector.processImage(img, drawImg) 
56+  # 
57+  #            label = label + \ 
58+  #                    "Head Detector : " + "\n" \ 
59+  #                                         "\t" + "direction : " + str(dicHead["direction"]) + "\n" 
60+  # 
61+  #        # GAZE 
62+  #        if self.main_window.selectMethodComboBox.currentIndex() == MainWindow.METHOD.EYE_HELP \ 
63+  #                and self.main_window.current_mode in [MainWindow.MODE.CHAIR, MainWindow.MODE.KEYBOARD]: 
64+  # 
65+  #            dicGaze = self.gaze_detector.processImage(img) 
66+  # 
67+  #            label = label + \ 
68+  #                    "Gaze Detector : " + "\n" \ 
69+  #                                         "\t" + "Gaze : " + str(dicGaze["direction"]) + "\n" 
70+  # 
71+  #            if dicGaze["img"] is not None: 
72+  #                self.gazeImg = dicGaze["img"] 
73+  #                self.gazeImg = toQImage(self.gazeImg) 
74+  #                self.gazeImg = self.gazeImg.rgbSwapped() 
75+  # 
76+  #            if self.gazeImg is not None: 
77+  #                self.main_window.gaze_image_label.setPixmap(QPixmap.fromImage(self.gazeImg)) 
78+  #            else: 
79+  #                self.main_window.gaze_image_label.setText("None") 
80+ 
81+ 
82+         # Blink and Gaze 
83+         _ , img  =  self .cap .read ()
84+         dicGaze  =  self .gaze_detector .processImage (img )
85+ 
86+         outImage  =  toQImage (dicGaze ["img" ])
8987        outImage  =  outImage .rgbSwapped ()
9088        self .main_window .main_image_label .setPixmap (QPixmap .fromImage (outImage ))
91-         self .main_window .image_info_textlabel .setText (label )
92- 
93-         if  dicBlink  is  not None :
94-             if  dicBlink ["left" ]:
95-                 if  self .main_window .selectMethodComboBox .currentIndex () ==  MainWindow .METHOD .HEAD_HELP :
96-                     self .face_detector .initPos (dicHead ["face" ])
97-                     return 
98-                 self .giveOutput ("blinkleft" )
99-                 return 
100-             elif  dicBlink ["right" ]:
101-                 self .giveOutput ("blinkright" )
102-                 return 
103-             elif  dicBlink ["both" ]:
104-                 self .giveOutput ("blinkboth" )
105-                 return 
106- 
107-         if  dicHead  is  not None :
108-             if  dicHead ["direction" ] !=  "not initialized" :
109-                 self .giveOutput (dicHead ["direction" ])
110-                 return 
111- 
112-         if  dicGaze  is  not None :
113-             if  dicGaze ["direction" ] !=  "not initialized" :
114-                 self .giveOutput (dicGaze ["direction" ])
115-                 return 
89+ 
90+         if  dicGaze ["gazeleft" ] is  not None :
91+             outImage  =  toQImage (dicGaze ["gazeleft" ])
92+             outImage  =  outImage .rgbSwapped ()
93+             self .main_window .left_gaze_label .setPixmap (QPixmap .fromImage (outImage ))
94+ 
95+         if  dicGaze ["gazeright" ] is  not None :
96+             outImage  =  toQImage (dicGaze ["gazeright" ])
97+             outImage  =  outImage .rgbSwapped ()
98+             self .main_window .right_gaze_label .setPixmap (QPixmap .fromImage (outImage ))
99+ 
100+         # if dicBlink is not None: 
101+         #     if dicBlink["left"]: 
102+         #         if self.main_window.selectMethodComboBox.currentIndex() == MainWindow.METHOD.HEAD_HELP: 
103+         #             self.face_detector.initPos(dicHead["face"]) 
104+         #             return 
105+         #         self.giveOutput("blinkleft") 
106+         #         return 
107+         #     elif dicBlink["right"]: 
108+         #         self.giveOutput("blinkright") 
109+         #         return 
110+         #     elif dicBlink["both"]: 
111+         #         self.giveOutput("blinkboth") 
112+         #         return 
113+ 
114+         # if dicHead is not None: 
115+         #     if dicHead["direction"] != "not initialized": 
116+         #         self.giveOutput(dicHead["direction"]) 
117+         #         return 
118+         # 
119+         # if dicGaze is not None: 
120+         #     if dicGaze["direction"] != "not initialized": 
121+         #         self.giveOutput(dicGaze["direction"]) 
122+         #         return 
116123
117124
118125def  toQImage (raw_img ):
0 commit comments