Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. # Mouse event handler for get_hsv
  2. def on_mouse(self, event, x, y, flag, param):
  3. if event == cv2.EVENT_LBUTTONDBLCLK:
  4. # Circle to indicate hsv location, and update frame
  5. cv2.circle(self.img_debug, (x, y), 3, (0, 0, 255))
  6. cv2.imshow('hsv_extractor', self.img_debug)
  7.  
  8. # Print values
  9. values = self.hsv_frame[y, x]
  10. print('H:', values[0], '\tS:', values[1], '\tV:', values[2])
  11.  
  12. def get_hsv(self):
  13. cv2.namedWindow('hsv_extractor')
  14. while True:
  15. self.grab_frame()
  16.  
  17. # Bottom ROI
  18. 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)
  19.  
  20. # Top ROI
  21. 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)
  22.  
  23. self.hsv_frame = cv2.cvtColor(self.img, cv2.COLOR_BGR2HSV)
  24.  
  25. # Mouse handler
  26. cv2.setMouseCallback('hsv_extractor', self.on_mouse, 0)
  27. cv2.imshow('hsv_extractor', self.img_debug)
  28.  
  29. key = cv2.waitKey(0) & 0xFF
  30. if key == ord('q'):
  31. break
  32. self.stop_camera()
  33. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement