OpenCV3.3-Python3.6.2中KNN使用举例
来源:互联网 发布:外文数据库免费入口 编辑:程序博客网 时间:2024/06/05 11:54
# reference: https://docs.opencv.org/3.1.0/d5/d26/tutorial_py_knn_understanding.html# opencv-3.3.0/doc/py_tutorials/py_ml/py_knn/py_knn_opencvimport cv2import numpy as npimport matplotlib.pyplot as plt# Feature set containing (x,y) values of 25 known/training datatrainData = np.random.randint(0, 100, (25,2)).astype(np.float32)# Labels each one either Red or Blue with numbers 0 and 1responses = np.random.randint(0, 2, (25,1)).astype(np.float32)# Take Red families and plot themred = trainData[responses.ravel() == 0]plt.scatter(red[:,0], red[:,1], 80, 'r', '^')# Take Blue families and plot themblue = trainData[responses.ravel() == 1]plt.scatter(blue[:,0], blue[:,1], 80, 'b', 's')#plt.show()# New comer is marked in green colornewcomer = np.random.randint(0, 100, (1,2)).astype(np.float32)plt.scatter(newcomer[:,0], newcomer[:,1], 80, 'g', 'o')knn = cv2.ml.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()
执行结果如下:
GitHub: https://github.com/fengbingchun/NN_Test
阅读全文
0 0
- OpenCV3.3-Python3.6.2中KNN使用举例
- OpenCV3.3中逻辑回归(Logistic Regression)使用举例
- OpenCV3.3中 K-最近邻法(KNN)接口简介及使用
- linux python3使用opencv3.2
- 在win10中python3安装opencv3
- OpenCV3的kNN算法进行OCR识别-使用Python
- OpenCV3中使用SVM
- OpenCV3.3 + Python3.6 开发环境配置
- win10中Anaconda(Python3.6)配置OpenCV3.3+深度神经网络实现
- python3.4+KNN
- kNN算法--Python3实现
- 在Python3.4中实现opencv3.1.0的安装配置
- 在Python3.4中实现opencv3.1.0的安装配置
- Ubuntu14 python3.5 visualvenv 中安装opencv3.1.0
- python3.5 opencv3.1 不能使用sift, surf。
- python3.5 上面使用 opencv/ opencv3.10/3.20
- Python3+Opencv3的安装
- python3 opencv3 help(cv2)
- kmp算法实例讲解
- 巨海集团商学院双十一特惠大礼包,给您一个增值的自己
- PreparedStatement 使用like 模糊查询
- 健康类App原型制作分享-Pillow
- Qt实例-UCF数据标注
- OpenCV3.3-Python3.6.2中KNN使用举例
- JDesktopPane改变窗体大小时背景图片自动适应窗体大小
- Redhat Linux 7.3网络服务无法启动解决办法
- checkbox js验证只有一个可选
- RNG类
- 检查文件是否存在于远程服务器上
- Tensorflow-Mask RCNN
- 常用开发工具介绍
- iOS开发实现HTTPS之 cer 文件的使用