Note that there are some explanatory texts on larger screens.

plurals
  1. POfit an ellipse through points
    primarykey
    data
    text
    <p>Using opencv for python I need to fit an ellipse (using cv2.fitEllipse) to the array of points returned by cv.FindCornerSubPix (here named 'features'). I have seen numerous examples of this on the internet, but I cannot figure it out. I figured cv.FindCornerSubPix returns an array of tuples, and my code triggered an error asking me for a numpy array as argument for cv2.fitEllipse, so I tried to convert 'features' to a numpy array and the error is now:</p> <p>'error: ......\src\opencv\modules\imgproc\src\contours.cpp:2019: error: (-215) points.checkVector(2) >= 0 &amp;&amp; (points.depth() == CV_32F || points.depth() == CV_32S)'</p> <p>on line 196 ('cv2.fitEllipse(ellipse)' at the end of my code), so I guess I am not feeding the right array format to cv2.fitEllipse. Would you please help me? The code below is just a modified version of the opencv sample lkdemo.py.</p> <pre><code> # search the good points features = cv.GoodFeaturesToTrack ( grey, eig, temp, MAX_COUNT, quality, min_distance, mask, 10, 0, 0.04) # refine the corner locations features = cv.FindCornerSubPix ( grey, features, (win_size, win_size), (-1, -1), (cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 20, 0.03)) elif features != []: # we have points, so display them # calculate the optical flow features, status, track_error = cv.CalcOpticalFlowPyrLK ( prev_grey, grey, prev_pyramid, pyramid, features, (win_size, win_size), 3, (cv.CV_TERMCRIT_ITER|cv.CV_TERMCRIT_EPS, 20, 0.03), flags) # set back the points we keep features = [ p for (st,p) in zip(status, features) if st] if add_remove_pt: # we have a point to add, so see if it is close to # another one. If yes, don't use it def ptptdist(p0, p1): dx = p0[0] - p1[0] dy = p0[1] - p1[1] return dx**2 + dy**2 if min([ ptptdist(pt, p) for p in features ]) &lt; 25: # too close add_remove_pt = 0 # draw the points as green circles for the_point in features: cv.Circle (image, (int(the_point[0]), int(the_point[1])), 3, (0, 255, 0, 0), -1, 8, 0) #Fit an ellipse array = np.array([tuple(i) for i in features]) ellipse = np.asarray(array) cv2.fitEllipse(ellipse) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload