generate functionTue, 20 Jun 2023

get pixel values of image with open cv using mouse and with this two values normalize the image

def get_colour(): img = cv2.imread(image_path) cv2.namedWindow('image') def pick_colour(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDBLCLK: pixel = img[y, x] print("Red: ", pixel[0]) print("Green: ", pixel[1]) print("Blue: ", pixel[2]) print("---------") color = pixel color = color.astype("float") / 255 return color cv2.setMouseCallback('image', pick_colour) while True: cv2.imshow("image", img) if cv2.waitKey(20) & 0xFF == 27: break cv2.destroyAllWindows()

Questions about programming?Chat with your personal AI assistant