Advertisement
dan-masek

Untitled

Feb 11th, 2024 (edited)
1,049
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. img = cv2.imread("pxpuz.jpg", cv2.IMREAD_COLOR)
  5. white_pixels = np.where(np.all(img == (255, 255, 255), axis=-1))
  6. # Make list of tuples (X, Y)
  7. white_coords = zip(white_pixels[1], white_pixels[0])
  8. # Sort in ascending order, by (Y, X)
  9. sorted_coords = sorted(white_coords, key=lambda v: (v[1], v[0]))
  10. if sorted_coords:
  11.     # First coordinate pair is the top-left most white pixel...
  12.     cv2.circle(img, sorted_coords[0], 5, (255, 0, 0), -1)
  13. cv2.imwrite("pxpuz_result.png", img)
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement