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 ...
随机推荐
- C语言函数库分类
- python监控rabbitmq的消息队列数量
[root@localhost chen]# cat b.py #!/usr/bin/python # -*- coding: UTF-8 -*- import json,time import re ...
- Spring cloud微服务安全实战-4-7重构代码以适应真实环境
现在有了认证服务器,也配置了资源服务器.也根据OAuth协议,基于令牌认证的授权也跑通了.基本的概念也有了简单的理解. 往下深入之前,有几个点,还需要说一下 使用scopes来控制权限,scopes可 ...
- 算法习题---5-6对称轴(UVa1595)
一:题目 判断平面上的一组点,是否关于一条竖线对称.即找到一条垂直对称轴 (一)样例输入 - (二)样例输出 YES NO YES 二:代码实现 #define _CRT_SECURE_NO_WARN ...
- [转]动态规划DP的分类
链接地址:http://www.cnblogs.com/Renyi-Fan/p/9285495.html
- CSS3 mask 遮罩蒙版效果
mask demo效果演示:http://dtdxrk.github.io/game/css3-demo/mask.html mask 的属性: -webkit-mask-image:url | gr ...
- 【嵌入式硬件Esp32】Ubuntu 1804下ESP32交叉编译环境搭建
一.ESP32概述EPS32是乐鑫最新推出的集成2.4GWi-Fi和蓝牙双模的单芯片方案,采用台积电(TSMC)超低功耗的40nm工艺,拥有最佳的功耗性能.射频性能.稳定性.通用性和可靠性,适用于多种 ...
- Swoole练习 安装
仅支持 Linux,FreeBSD,MacOS,3类操作系统 Linux 内核版本 2.3.32 以上 PHP-5.3.10 以上版本,包括PHP7 gcc4.4 以上版本或者clang cmake2 ...
- C++ STL-bitset
1.bitset的声明 #include <bitset> using std::bitset; 2.bitset对象的定义和初始化 可以如下声明一个该类型变量: bitset ...
- 乐字节Java继承|方法重写、super和final关键字
大家好,乐字节的小乐又来了,上一篇是:乐字节Java|JavaBean.继承与权限修饰,也是属于Java继承的,今天继续Java继承. 一. 方法的重写 父类不满足子类的要求,按需改写.注意 方法签名 ...