Ask Your Question

Revision history [back]

numpy.where() on grayscale frame, wrong indices

0 down vote favorite

I'm trying to implement a basic RANSAC algorithm for the detection of a circle in a grayscale image.

The problem is that, after I thresholded the image and I search for non-zero pixels I get the right shape, but the points are somehow delocalized from the original position:

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

image description