0

I am using Python3 and OpenCV to detect green dots in the following image:

Detected green dots via mask with OpenCV

The code for this is as follows:

import cv2
import numpy as np

img = cv2.imread("dot_test.png")
rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

lower_range = np.array([0, 250, 80])
upper_range = np.array([5, 255, 88])

mask = cv2.inRange(rgb, lower_range, upper_range)

cv2.imshow("Image", img)
cv2.imshow("Mask", mask)

cv2.waitKey(0)
cv2.destroyAllWindows()

Assuming the number of dots in dot_test.png is variable, I would like to store the coordinates of each dot in an array and iterate through them printing specific text. What would a good approach to accomplishing this be? I am a bit lost at this point.

snoozesec
  • 11
  • 1
  • You now need to get the connectedComponents. This will check the pixels in your mask and compare it to neighboring pixels to determine if they are part of the same "object". An example can be found [here](https://stackoverflow.com/a/46442154/11402024) – Roqux Apr 23 '20 at 21:36
  • I would suggest using cv2.findContours() from the black/white image and then the centroids of the contours. Those points can be used to locate where you want to put your text. – fmw42 Apr 23 '20 at 22:43

0 Answers0