Created
June 26, 2016 04:26
-
-
Save kendricktan/337d4053c3ab00f6678be9a201c897e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment