Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- img = cv2.imread("pxpuz.jpg", cv2.IMREAD_COLOR)
- white_pixels = np.where(np.all(img == (255, 255, 255), axis=-1))
- # Make list of tuples (X, Y)
- white_coords = zip(white_pixels[1], white_pixels[0])
- # Sort in ascending order, by (Y, X)
- sorted_coords = sorted(white_coords, key=lambda v: (v[1], v[0]))
- if sorted_coords:
- # First coordinate pair is the top-left most white pixel...
- cv2.circle(img, sorted_coords[0], 5, (255, 0, 0), -1)
- cv2.imwrite("pxpuz_result.png", img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement