我想检测尺寸为(3000,2000,3)的图像的点(x,y)坐标.这类图像的示例如下所示:
为了处理图像,我使用以下代码:
img = cv2.imread(path_dots_data + "01000.exr", cv2.IMREAD_ANYCOLOR |cv2.IMREAD_ANYDEPTH | cv2.IMREAD_UNCHANGED)
img = img - dark_img
img = img / img.max()
img = np.clip(a = img, a_min = 0.0, a_max = 1.0)
# Multiply by 255 before converting to uint 8 dtype-
img = img * 255.0
# Convert to uint8 dtype for opencv2 algos to work-
img = img.astype('uint8')
# Apply blurring to suppress high-frequency signals-
blur = cv2.medianBlur(img, 5)
# Convert from color to gray-scale-
gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
# Apply thresholding to detect white dots on black background-
thresh = cv2.threshold(gray * 5, 200, 255, cv2.THRESH_BINARY)[1]
# Apply findCountours()-
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
len(cnts)
# 41
# Add circles around detected contours-
min_area = 0.1
white_dots = []
for c in cnts:
area = cv2.contourArea(c)
if area > min_area:
cv2.drawContours(img, [c], -1, (36, 255, 12), 2)
white_dots.append(c)
# The final output looks like:
plt.figure(figsize = (12, 10))
plt.imshow(img, cmap = 'gray')
plt.show()
我的问题是:在第二个输出图像中有how can I find the (x, y) coordinates for the center of the detected contours/circles条(绿线)?