Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knearest compatibility error (OpenCV 3.1) #4

Closed
franktoffel opened this issue Feb 19, 2017 · 4 comments
Closed

Knearest compatibility error (OpenCV 3.1) #4

franktoffel opened this issue Feb 19, 2017 · 4 comments

Comments

@franktoffel
Copy link

Again, some errors due to a series of refactoring operations made in the latest versions:

Ejemplo 22, line 25,26 and 27 crash:

knn = cv2.KNearest() # error
knn.train(trainData, responses)  # error
ret, results, neighbours, dist = knn.find_nearest(newcomer, k)  # error


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-cfe065aacd5a> in <module>()
     23 # Classification
     24 k = 5
---> 25 knn = cv2.KNearest()
     26 knn.train(trainData, responses)
     27 ret, results, neighbours, dist = knn.find_nearest(newcomer, k)

AttributeError: module 'cv2' has no attribute 'KNearest'

This version works:

knn = cv2.ml.KNearest_create()
knn.train(trainData,cv2.ml.ROW_SAMPLE,responses)
ret, results, neighbours, dist = knn.findNearest(newcomer, k)

+info:
http://stackoverflow.com/a/30950853
http://stackoverflow.com/a/32990528
http://stackoverflow.com/a/34247966

@rcrespocano
Copy link
Owner

Fixed error.

Thank you so much.

@aj-amitjain
Copy link

It worked. Thanks

@Tulsi97
Copy link

Tulsi97 commented Jun 9, 2018

it's working,thanks

@SUNILARAVA
Copy link

The below code worked for me also...

knn = cv2.ml.KNearest_create()
knn.train(trainData,cv2.ml.ROW_SAMPLE,responses)
ret, results, neighbours, dist = knn.findNearest(newcomer, k)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants