官术网_书友最值得收藏!

Training the classifier

Now it's time to train the classifier.

As with all other machine learning functions, the k-NN classifier is part of OpenCV 3.1's ml module. We can create a new classifier using the following command:

In [15]: knn = cv2.ml.KNearest_create()
In the older versions of OpenCV, this function might be called cv2.KNearest() instead.

We then pass our training data to the train method:

In [16]: knn.train(train_data, cv2.ml.ROW_SAMPLE, labels)
Out[16]: True

Here, we have to tell knn that our data is an N x 2 array (that is, every row is a data point). Upon success, the function returns True.

主站蜘蛛池模板: 安图县| 宁河县| 阳朔县| 临西县| 辽宁省| 龙口市| 宣威市| 正安县| 永定县| 霞浦县| 乡宁县| 晋城| 皮山县| 潼关县| 新丰县| 邵武市| 金平| 安龙县| 政和县| 宁明县| 凌源市| 鲜城| 济源市| 太原市| 如东县| 板桥市| 招远市| 拉萨市| 方正县| 孟津县| 兴义市| 中江县| 渭源县| 长子县| 宜兰县| 长顺县| 合水县| 澄城县| 小金县| 固镇县| 兰溪市|