- Machine Learning for OpenCV
- Michael Beyeler
- 101字
- 2021-07-02 19:47:22
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.
推薦閱讀
- Advanced Splunk
- Visual Basic .NET程序設計(第3版)
- JavaScript+DHTML語法與范例詳解詞典
- C語言最佳實踐
- Silverlight魔幻銀燈
- Java設計模式及實踐
- Apex Design Patterns
- Python機器學習算法: 原理、實現與案例
- CoffeeScript Application Development Cookbook
- Test-Driven Development with Django
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- Python編程:從入門到實踐(第3版)
- 現代CPU性能分析與優化
- Visual Basic 程序設計實踐教程
- Clojure Web Development Essentials