相关疑难解决方法(0)

KNN train()in cv2 with opencv 3.0

我正在尝试使用cv2(python 2.7)和opencv 3.0运行k最近邻居.我使用http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_ml/py_knn/py_knn_understanding/py_knn_understanding.html等代码复制了相同的错误消息:

import cv2
import numpy as np
import matplotlib.pyplot as plt
# 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')

#The following line is modified for OpenCV 3.0
knn …
Run Code Online (Sandbox Code Playgroud)

python knn opencv3.0

20
推荐指数
1
解决办法
1万
查看次数

标签 统计

knn ×1

opencv3.0 ×1

python ×1