Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.ml_KNearest object has no attribute find_nearest

Tags:

python

opencv

I am a beginner in openCV and am trying to execute a given piece of code.I am using Python 2.7 with OpenCV3.0.

The previous code was in an earlier version of OpenCV and so it had used KNearest which I modified as cv2.ml.KNearest_create() as suggested by this post OpenCV 3.0.0-beta missing KNN?

Now when I am trying to access the findnearest method, I am getting an error: cv2.ml.knearest object has no attribute find_nearest

Below is the code sample

model = cv2.ml.KNearest_create()

roi = dilate[by:by+bh,bx:bx+bw]
small_roi = cv2.resize(roi,(10,10))
feature = small_roi.reshape((1,100)).astype(np.float32)
ret,results,neigh,dist = model.find_nearest(feature,k=1)

Is there any change in the method name in OpenCV3.0?

like image 636
TheFallenOne Avatar asked Dec 13 '15 02:12

TheFallenOne


1 Answers

I replaced the find_nearest with findNearest and it worked like a charm.

So I believe findNearest is the version of find_nearest in OpenCV3.0.

like image 50
TheFallenOne Avatar answered Nov 06 '22 17:11

TheFallenOne