我试图通过点击它来交互式获取图像中的点。为此,我使用matplotlib提供的pyplot包和Python2.7。
我是按照以下方式进行的:
fig = plt.figure()
self.ax = fig.add_subplot(111)
self.ax.imshow(self.image, cmap='gray')
self.ax.axis('image')
self.original_points = plt.ginput(self.clicks, mouse_stop = 3, mouse_pop = 2)
self.image[self.original_points[0]]
但是给了我以下错误:
IndexError: index 382 is out of bounds for axis 0 with size 362
似乎x和y坐标相反。发生了什么事?
答案 0 :(得分:1)
是的,ginput
会返回点击点的(x,y)
坐标。所以你需要颠倒顺序。
另请注意,您将获得浮点坐标,因此在使用它们对图像建立索引之前,应确保将类型更改为int
。