- 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.
推薦閱讀
- Twilio Best Practices
- Getting Started with CreateJS
- OpenCV 3和Qt5計算機視覺應(yīng)用開發(fā)
- Bulma必知必會
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- 深入淺出Serverless:技術(shù)原理與應(yīng)用實踐
- MATLAB for Machine Learning
- Java高并發(fā)核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Hands-On GUI Programming with C++ and Qt5
- Kubernetes進階實戰(zhàn)
- Python Digital Forensics Cookbook
- 編程的原則:改善代碼質(zhì)量的101個方法
- C#程序開發(fā)參考手冊
- jQuery Essentials