numpy.where()在灰度帧上,错误的索引?

时间:2015-06-06 10:59:16

标签: python opencv numpy matplotlib ransac

我试图实现基本的RANSAC算法来检测灰度图像中的圆。

问题在于,在我对图像进行阈值处理并搜索非零像素后,我得到了正确的形状,但这些点在某种程度上与原始位置不相关:

video = cv2.VideoCapture('../video/01_CMP.avi')
video.set(cv2.CAP_PROP_POS_FRAMES,200)
succ, frame = video.read()

frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
frame = cv2.normalize(frame,frame, alpha=0,norm_type=cv2.NORM_MINMAX, beta = 255)
ret,frame = cv2.threshold(frame,35,255,cv2.THRESH_BINARY)

points = n.where(frame>0) #Thresholded pixels

#Orienting correctly the points in a (n,2) shape
#needed because of arguments of circle.points_distance()
points = n.transpose(n.vstack([points[0],points[1]]))

plt.imshow(frame,cmap='gray');
plt.plot(points[:,0],points[:,1],'wo')

video.release()

Non-zero pixels, wrong position

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

OpenCV使用NumPy ndarray来表示图像,数组的轴0是垂直的,对应于图像的Y轴。

因此,要绘制所需的点数:plt.plot(points[:,1],points[:,0],'wo')