module 'cv2' has no attribute 'KNearest_create'
python版本:3.6.5
opencv版本:3.2.0
使用的是jupyter notebook
源代码如下:
import cv2
import numpy as np
import matplotlib.pyplot as plt %matplotlib inline # Feature set containing (x,y) values of 25 known/training data
trainData = np.random.randint(0,100,(25,2)).astype(np.float32) # Labels each one either Red or Blue with numbers 0 and 1
responses = np.random.randint(0,2,(25,1)).astype(np.float32) # Take Red families and plot them
red = trainData[responses.ravel()==0]
plt.scatter(red[:,0],red[:,1],80,'r','^') # Take Blue families and plot them
blue = trainData[responses.ravel()==1]
plt.scatter(blue[:,0],blue[:,1],80,'b','s') # plt.show() newcomer = np.random.randint(0,100,(1,2)).astype(np.float32)
plt.scatter(newcomer[:,0],newcomer[:,1],80,'g','o') knn = cv2.KNearest_create() knn.train(trainData,cv2.ml.ROW_SAMPLE,responses)
ret, results, neighbours ,dist = knn.findNearest(newcomer, 3) print ("result: ", results,"\n")
print ("neighbours: ", neighbours,"\n")
print ("distance: ", dist) plt.show()
出现的错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-18-35bac89cb177> in <module>()
18 plt.scatter(newcomer[:,0],newcomer[:,1],80,'g','o')
19
---> 20 knn = cv2.KNearest_create()
21
22 knn.train(trainData,cv2.ml.ROW_SAMPLE,responses) AttributeError: module 'cv2' has no attribute 'KNearest_create'
解决方法:
opencv官方教程中的是opencv2的版本
在3中需要使用
cv2.ml.KNearest_create()
参考链接:https://stackoverflow.com/questions/34247502/cv2-ml-knearest-object-has-no-attribute-find-nearest
module 'cv2' has no attribute 'KNearest_create'的更多相关文章
- AttributeError: module 'cv2' has no attribute 'SIFT'解决总结
AttributeError: module 'cv2' has no attribute 'SIFT' 遇到该问题时,网友多是建议补个包,即pip install opencv-contrib-py ...
- OpenCV 学习笔记 05 人脸检测和识别 AttributeError: module 'cv2' has no attribute 'face'
1 环境设置: win10 python 3.6.8 opencv 4.0.1 2 尝试的方法 在学习人脸识别中,遇到了没有 cv2 中没有 face 属性.在网上找了几个方法,均没有成功解决掉该问题 ...
- AttributeError: 'module' object has no attribute 'face'
报错 raceback (most recent call last): File "D:/work/python/face_ai/predict.py", line 41, in ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- attributeError:'module' object has no attribute ** 解决办法
写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...
- AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'
/*************************************************************************** * AttributeError: 'modu ...
- 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7
最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...
- AttributeError: 'module' object has no attribute 'Thread'
$ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last): File "th ...
随机推荐
- MySQL not equal to operator <> && !=
MySQL :: MySQL 5.7 Reference Manual :: 12.3.2 Comparison Functions and Operatorshttps://dev.mysql.co ...
- ubuntu安装IntelliJ Idea及图标创建
一.下载并解压安装 二.创建桌面程序 1. cd /usr/local/applications/ 2. vi idea.desktop 3. 内容如下 [Desktop Entry] Name=In ...
- pyqt5界面
用pyqt5做了一个小程序,保留一下这个固定格式: import sys from PyQt5 import uic, QtGui from PyQt5.QtGui import QWindow fr ...
- Leetcode: 24 Game
You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated ...
- Selenium踩坑记之iFrame的定位与切换
转自:https://www.jianshu.com/p/6e7d0359e4bb Selenium是浏览器自动化测试的工具之一,用过的人都懂他的好,也被他坑的不要不要的.今天就聊聊Selenium的 ...
- 泡泡一分钟:FMD Stereo SLAM: Fusing MVG and Direct Formulation Towards Accurate and Fast Stereo SLAM
FMD Stereo SLAM: Fusing MVG and Direct Formulation Towards Accurate and Fast Stereo SLAM FMD Stereo ...
- C/C++代码静态分析工具调研
C/C++代码静态分析工具调研 摘自:https://www.jianshu.com/p/92886d979401 简述 静态分析(static analysis)是指在不执行代码的情况下对其进行分析 ...
- 数据结构与抽象 Java语言描述 第4版 pdf (内含标签)
数据结构与抽象 Java语言描述 第4版 目录 前言引言组织数据序言设计类P.1封装P.2说明方法P.2.1注释P.2.2前置条件和后置条件P.2.3断言P.3Java接口P.3.1写一个接口P.3. ...
- ABAP DEMO so批量导入
*&---------------------------------------------------------------------* *& Report YDEMO_015 ...
- MVC ViewBag和ViewData的使用
ViewBag public ActionResult About() { ViewBag.Message = "Your application description page.&quo ...