【问题标题】:Using cv2 to import coordinates of an image into Python. Coordinates, do not return image correctly when plotted after import使用 cv2 将图像的坐标导入 Python。坐标,导入后绘制时不正确返回图像
【发布时间】:2020-11-28 19:00:58
【问题描述】:

我已导入图像 ,然后将角分配给 x 和 y 坐标:

# Import image and define coords.
def image_read():
img = cv2.imread('initlayout.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)

corners = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)
corners = np.int0(corners)
x = []
y = []
for corner in corners:
    a, b = corner.ravel()
    x.append(a)
    y.append(b)
No_vertices = len(x)
return x, y, No_vertices

但现在当我使用以下代码绘制形状时:

# Plot the polygon.
def plotter(x, y):
x.append(x[0])
y.append(y[0])
figure()
plot(x, y)
show()

我发现坐标顺序不正确,因为生成的图像是

关于如何使十字架显示与此类似,但使用原始图像中的坐标的任何建议?

【问题讨论】:

    标签: python arrays python-3.x image cv2


    【解决方案1】:

    contract for goodFeaturesToTrack 不保证功能顺序。它似乎从图像顶部向下工作,从左到右扫描,这是完全明智的做法,尽管它不适合您的需求。

    根据您的需求,findContours 可能会带来更好的运气。 findContours here 有一个平易近人的演练。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多