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

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.

主站蜘蛛池模板: 安康市| 武山县| 梁平县| 固镇县| 漳州市| 天镇县| 景泰县| 通山县| 绥中县| 迁西县| 施甸县| 海安县| 新龙县| 育儿| 沙坪坝区| 嘉兴市| 防城港市| 东山县| 东乌| 常山县| 平定县| 麻栗坡县| 开鲁县| 陵川县| 阳朔县| 吉木乃县| 阜宁县| 嘉黎县| 盐源县| 阿拉尔市| 蓬莱市| 合川市| 深水埗区| 巨鹿县| 延庆县| 西贡区| 开封市| 南漳县| 石台县| 荣成市| 六安市|