答案 0 :(得分:0)
首先将图像转换为HSV并分离出红点。然后通过查找轮廓和它们的时刻来获得其坐标。如果您使用的是OpenCV -
<强>输出:强>
<强>代码:强>
import cv2
import numpy as np
frame=cv2.imread("dots.jpg")
dots=np.zeros_like(frame)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_hsv = np.array([112, 176, 174])
higher_hsv = np.array([179,210,215])
mask = cv2.inRange(hsv, lower_hsv, higher_hsv)
cnts, h = cv2.findContours( mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
mnts = [cv2.moments(cnt) for cnt in cnts]
centroids = [( int(round(m['m10']/m['m00'])),int(round(m['m01']/m['m00'])) ) for m in mnts]
for c in centroids:
cv2.circle(dots,c,5,(0,255,0))
print c
cv2.imshow('red_dots', dots)
cv2.waitKey(0)
cv2.destroyAllWindows()