我想检测尺寸为(3000,2000,3)的图像的点(x,y)坐标.这类图像的示例如下所示:

input image

为了处理图像,我使用以下代码:

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()

final image output

我的问题是:在第二个输出图像中有how can I find the (x, y) coordinates for the center of the detected contours/circles条(绿线)?

推荐答案

看起来每个轮廓的质心可能与内部的亮点相匹配.看看这是否起作用:

for c in cnts:
    M = cv2.moments(c)
    cx = int(M['m10']/M['m00'])
    cy = int(M['m01']/M['m00'])
    cv2.circle(img, (cy, cx), 5, (0, 0, 255))
    

这应该在每个点cy,cx周围画一个红色圆圈,它应该与明亮的点相匹配

Python-3.x相关问答推荐

我的SELECT函数搜索的是列,而不是列中的数据.我怎么才能让它搜索数据呢?

正则表达式匹配并提取括号前的单词

如何定义既允许固定单词又允许模式的pydanti.BaseModel?

被多个\n拆分并保留

我正在try 从 10*3 矩阵中删除随机值并将其变为 10*2 矩阵

将两列的乘积连续添加到一列的累积和中

添加任意数量的 pandas 数据框

使用 iloc 或 loc 对多列进行过滤

移动所有列的数据帧值以使其单调递增

安装没有 sudo 权限的 python3 和 pip3

有没有一种方法可以通过输入从 0 到 255 的 R、G 和 B 值来生成 RGB colored颜色 ,而无需使用 python 中的 matplotlib 模块?

asyncio.as_completed() 应该接受 `Iterable`,但如果输入是 `Generator` 就会崩溃?

Python多进程:运行一个类的多个实例,将所有子进程保留在内存中

spaCy 中的匹配模式返回空结果

Pythonic,自定义警告

为什么包含类的名称不被识别为返回值函数注释?

创建日志(log)文件

Python中的依赖倒置

Python 的 unittest 和 unittest2 模块有什么区别?

0 是 0 == 0(#evaluates 为真?)