class KinectLayout(BaseLayout): def _create_custom_layout(self): pass def _init_custom_layout(self): self.hand_gestures = HandGestureRecognition() def _acquire_frame(self): frame, _ = freenect.sync_get_depth() # return success if frame size is valid if frame is not None: return (True, frame) else: return (False, frame) def _process_frame(self, frame): # clip max depth to 1023, convert to 8-bit grayscale np.clip(frame, 0, 1023, frame) frame >>= 2 frame = frame.astype(np.uint8) num_fingers, img_draw = self.hand_gestures.recognize(frame) height, width = frame.shape[:2] cv2.circle(img_draw, (width/2, height/2), 3, [255, 102, 0], 2) cv2.rectangle(img_draw, (width/3, height/3), (width*2/3, height*2/3), [255, 102, 0], 2) cv2.putText(img_draw, str(num_fingers), (30, 30),cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255)) return img_draw
class KinectLayout(BaseLayout): def _create_custom_layout(self): pass def _init_custom_layout(self): self.hand_gestures = HandGestureRecognition() def _acquire_frame(self): frame, _ = freenect.sync_get_depth() # return success if frame size is valid if frame is not None: return (True, frame) else: return (False, frame) def _process_frame(self, frame): # clip max depth to 1023, convert to 8-bit grayscale np.clip(frame, 0, 1023, frame) frame >>= 2 frame = frame.astype(np.uint8) num_fingers, img_draw = self.hand_gestures.recognize(frame) height, width = frame.shape[:2] cv2.circle(img_draw, (width / 2, height / 2), 3, [255, 102, 0], 2) cv2.rectangle(img_draw, (width / 3, height / 3), (width * 2 / 3, height * 2 / 3), [255, 102, 0], 2) cv2.putText(img_draw, str(num_fingers), (30, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255)) return img_draw
class KinectLayout(BaseLayout): """Custom layout for Kinect display A plain GUI layout for Kinect output. We overwrite the BaseLayout's _acquire_frame method to acquire a new frame from the depth sensor instead. """ def _init_custom_layout(self): """Initializes hand gesture recognition""" self.hand_gestures = HandGestureRecognition() def _create_custom_layout(self): """Use plain layout""" pass def _acquire_frame(self): """Acquire frame from depth sensor using freenect library""" frame, _ = freenect.sync_get_depth() # return success if frame size is valid if frame is not None: return (True, frame) else: return (False, frame) def _process_frame(self, frame): """Recognizes hand gesture in a frame of the depth sensor""" # clip max depth to 1023, convert to 8-bit grayscale np.clip(frame, 0, 2**10 - 1, frame) frame >>= 2 frame = frame.astype(np.uint8) # recognize hand gesture num_fingers, img_draw = self.hand_gestures.recognize(frame) # draw some helpers for correctly placing hand height, width = frame.shape[:2] cv2.circle(img_draw, (width / 2, height / 2), 3, [255, 102, 0], 2) cv2.rectangle(img_draw, (width / 3, height / 3), (width * 2 / 3, height * 2 / 3), [255, 102, 0], 2) # print number of fingers on image cv2.putText(img_draw, str(num_fingers), (30, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255)) return img_draw
class KinectLayout(BaseLayout): """Custom layout for Kinect display A plain GUI layout for Kinect output. We overwrite the BaseLayout's _acquire_frame method to acquire a new frame from the depth sensor instead. """ def _init_custom_layout(self): """Initializes hand gesture recognition""" self.hand_gestures = HandGestureRecognition() def _create_custom_layout(self): """Use plain layout""" pass def _acquire_frame(self): """Acquire frame from depth sensor using freenect library""" frame, _ = freenect.sync_get_depth() # return success if frame size is valid if frame is not None: return (True, frame) else: return (False, frame) def _process_frame(self, frame): """Recognizes hand gesture in a frame of the depth sensor""" # clip max depth to 1023, convert to 8-bit grayscale np.clip(frame, 0, 2**10 - 1, frame) frame >>= 2 frame = frame.astype(np.uint8) # recognize hand gesture num_fingers, img_draw = self.hand_gestures.recognize(frame) # draw some helpers for correctly placing hand height, width = frame.shape[:2] cv2.circle(img_draw, (width/2, height/2), 3, [255, 102, 0], 2) cv2.rectangle(img_draw, (width/3, height/3), (width*2/3, height*2/3), [255, 102, 0], 2) # print number of fingers on image cv2.putText(img_draw, str(num_fingers), (30, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255)) return img_draw
def _init_custom_layout(self): """Initializes hand gesture recognition""" self.hand_gestures = HandGestureRecognition()
def _init_custom_layout(self): self.hand_gestures = HandGestureRecognition()