OpenCV 3.0.0-beta missing KNN?

一笑奈何 提交于 2020-01-10 03:11:05

问题


Having just upgraded from opencv-2.4.11, KNearest seems to be missing

In [27]: import cv2
In [28]: print(cv2.__version__)
3.0.0-beta

In [29]: cv2.KNearest()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-d2ea29abad59> in <module>()
----> 1 cv2.KNearest()

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

In [30]: cv2.K
cv2.KAZE_DIFF_CHARBONNIER      cv2.KAZE_DIFF_WEICKERT         cv2.KMEANS_RANDOM_CENTERS      cv2.KeyPoint
cv2.KAZE_DIFF_PM_G1            cv2.KAZE_create                cv2.KMEANS_USE_INITIAL_LABELS  cv2.KeyPoint_convert
cv2.KAZE_DIFF_PM_G2            cv2.KMEANS_PP_CENTERS          cv2.KalmanFilter               cv2.KeyPoint_overlap

回答1:


Many modules were removed from OpenCV core and marked as nonfree. These modules have separate repository and has to be built separately.

The repository is here https://github.com/itseez/opencv_contrib/

The info was found in this answer https://stackoverflow.com/a/27419092/892914




回答2:


In reality, KNearest has been moved to module cv2.ml in opencv3, and you have to call cv2.ml.KNearest_create() for using knn.

In [1]: import cv2

In [2]: cv2.__version__
Out[2]: '3.0.0'

In [3]: cv2.ml.KNea
cv2.ml.KNearest_BRUTE_FORCE  cv2.ml.KNearest_create   cv2.ml.KNearest_KDTREE

In [3]: cv2.ml.KNearest_create

For more details, please run help(cv2.ml.KNearest_create()).

Enjoy :)



来源:https://stackoverflow.com/questions/29369907/opencv-3-0-0-beta-missing-knn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!