multithreading - Opencv Multithreaded Python - Currently is not working as intended -


code:

def video_stream(self):     while(true):           # our operations on frame come here          gray = cv2.cvtcolor(img, cv2.color_bgr2gray)         faces = self.face_cascade.detectmultiscale(gray, 1.3, 5)         while(faces == ()):             faces = self.face_cascade.detectmultiscale(gray, 1.3, 5)          if faces not ():             if faces[0][0] < 500: # head on left                 #cmd = """osascript -e 'tell application "system events" keystroke "f"'"""                 print "right"                 #.system(cmd)             else: # head on right                 #cmd = """osascript -e 'tell application "system events" keystroke "d"'"""                 print "left"                 #os.system(cmd)    def main(self):     t = threading.thread(target = self.video_stream)     t.start()      while not self.done:         self.event_loop()         self.update()         pg.display.update()         self.clock.tick(self.fps)         if self.show_fps:             fps = self.clock.get_fps()             with_fps = "{} - {:.2f} fps".format(self.caption, fps)             pg.display.set_caption(with_fps) 

my question opencv multithreaded? code isn't complete, gives picture of trying do.

the main function runs mario game. program starts. starts thread video_stream runs simple face detection algorithm. if face present, there hardcoded threshold set (500) determines approximately face in respect camera. ideally, trigger keyboard event (via applescript) caught mario game. mario game controlled left , right via position of face.

the problem is, code running extremely slow. independently, both functions run smoothly. however, when threaded together, runs extremely slow. video_stream function misses lot of face detections.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -