【发布时间】:2022-01-26 01:56:49
【问题描述】:
我正在使用颜色查找坐标,在我的例子中假设为蓝色,并给出图像中具有该颜色的那个点的坐标。
我正在使用此代码:
#!/usr/bin/env python3
import cv2
import numpy as np
#Load image
img = cv2.imread('image.png')
#Define the blue color we want to find
blue = [255,0,0]
#Get X and Y cooridinates of ALL blue pixels
X,Y = np.where(np.all(img==blue, axis=2))
zipped = np.column_stack((X,Y))
#Get the number of coordinates founded
print(len(zipped))
我将蓝色区域中的所有像素都涂上颜色,而我只需要该特定位置的一个坐标。
此图像包含image_with_blue_coordinates 蓝色坐标(但每个蓝色点至少包含 6 到 8 个蓝色像素),所以我得到了所有坐标,而我只需要中心像素。
关于如何处理这个问题并且只获得 36 个 x,y 坐标而不是 1342 个的任何想法?
提前致谢
参考:Find the coordinates in an image where a specified colour is detected
【问题讨论】:
-
连接组件标记,或 findContours,或 SimpleBlobDetector
标签: python opencv image-processing colors coordinates