I want to detect squares on my screen and return a list of coordinates for each square.
I use color pixel detection(RGB) to detect the squares
def find_pixel_coordinates(target_color, image):
screenshot_array = np.array(image)
indices = np.argwhere(np.all(screenshot_array == target_color, axis=-1))
if len(indices) == 0:
return []
coordinates = [(idx[1], idx[0]) for idx in indices]
return coordinates
There are 2 green squares on the image the output looks like this
[(317, 127), (318, 127), (319, 127), (320, 127), (307, 128), (308, 128), (309, 128), (310, 128), (311, 128), (312, 128), (313, 128), (314, 128), (298, 129), (299, 129), (300, 129), (301, 129), (302, 129), (303, 129), (304, 129), (305, 129), (292, 130), (293, 130), (294, 130), (295, 130), (321, 130), (292, 131), (321, 131), (293, 133), (322, 133), (293, 134), (322, 134), (294, 136), (323, 136), (362, 263), (331, 264), (331, 265), (363, 265), (363, 266), (332, 267), (332, 268), (364, 268), (332, 269), (363, 269), (364, 269), (358, 270), (359, 270), (360, 270), (333, 271), (353, 271), (354, 271), (355, 271), (333, 272), (348, 272), (349, 272), (350, 272), (343, 273), (344, 273), (345, 273), (334, 274), (338, 274), (339, 274), (340, 274), (334, 275), (335, 275)...]
How do I detect which x,y coordinates belong to which square?