Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Mouse event handler for get_hsv
- def on_mouse(self, event, x, y, flag, param):
- if event == cv2.EVENT_LBUTTONDBLCLK:
- # Circle to indicate hsv location, and update frame
- cv2.circle(self.img_debug, (x, y), 3, (0, 0, 255))
- cv2.imshow('hsv_extractor', self.img_debug)
- # Print values
- values = self.hsv_frame[y, x]
- print('H:', values[0], '\tS:', values[1], '\tV:', values[2])
- def get_hsv(self):
- cv2.namedWindow('hsv_extractor')
- while True:
- self.grab_frame()
- # Bottom ROI
- cv2.rectangle(self.img_debug, (0, cvsettings.HEIGHT_PADDING_BOTTOM-2), (cvsettings.CAMERA_WIDTH, cvsettings.HEIGHT_PADDING_BOTTOM + cvsettings.IMG_ROI_HEIGHT + 2), (0, 250, 0), 2)
- # Top ROI
- cv2.rectangle(self.img_debug, (0, cvsettings.HEIGHT_PADDING_TOP-2), (cvsettings.CAMERA_WIDTH, cvsettings.HEIGHT_PADDING_TOP + cvsettings.IMG_ROI_HEIGHT + 2), (0, 250, 0), 2)
- self.hsv_frame = cv2.cvtColor(self.img, cv2.COLOR_BGR2HSV)
- # Mouse handler
- cv2.setMouseCallback('hsv_extractor', self.on_mouse, 0)
- cv2.imshow('hsv_extractor', self.img_debug)
- key = cv2.waitKey(0) & 0xFF
- if key == ord('q'):
- break
- self.stop_camera()
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement