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 ...
随机推荐
- Springboot配置文件获取系统环境变量的值
注意,这里说的是获取系统环境变量的值,譬如Windows里配置的JAVA_HOME之类的,可以直接在Springboot的配置文件中获取. 我们经常使用一些docker管理平台,如DaoCloud.r ...
- ffmpeg x264安装
fmpeg安装第三方编码器(encoder)库,ffmpeg编码h264(完) ffmpeg安装第三方编码器(encoder)库 关键词:ffmpeg.编码h264.第三方encoder 安装好了ff ...
- Java基础 return 退出main方法的示例
JDK :OpenJDK-11 OS :CentOS 7.6.1810 IDE :Eclipse 2019‑03 typesetting :Markdown code ...
- shell编程系列11--文本处理三剑客之sed利用sed删除文本中的内容
shell编程系列11--文本处理三剑客之sed利用sed删除文本中的内容 删除命令对照表 命令 含义 1d 删除第一行内容 ,10d 删除1行到10行的内容 ,+5d 删除10行到16行的内容 /p ...
- 微信小程序与Html交互
微信小程序与H5页面交互 https://www.jianshu.com/p/22e951d83841
- C++构造函数以及何时被调用
using namespace std; class A { public: A() { cout << "默认无参构造函数" << endl; } #if ...
- 转 mysql mysql命令行中执行sql的几种方式总结
https://www.jb51.net/article/96394.htm 1.直接输入sql执行 MySQL> select now(); +---------------------+ | ...
- 123457123456#0#----com.ppGame.HappyShuXue54--前拼后广--儿童数学_pp
com.ppGame.HappyShuXue54--前拼后广--儿童数学_pp
- Python - Django - Cookie 简单用法
home.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 单独配置的nginx mysql 重启
/usr/local/mysql/bin/mysqld_safe /usr/local/nginx/sbin/nginx -s stop /usr/local/nginx/sbin/nginx