- Machine Learning for OpenCV
- Michael Beyeler
- 124字
- 2021-07-02 19:47:22
Implementing k-NN in OpenCV
Using OpenCV, we can easily create a k-NN model via the cv2.ml.KNearest_create() function. Building the model then involves the following steps:
- Generate some training data.
- Create a k-NN object for a given number k.
- Find the k nearest neighbors of a new data point that we want to classify.
- Assign the class label of the new data point by majority vote.
- Plot the result.
We first import all the necessary modules: OpenCV for the k-NN algorithm, NumPy for data munging, and Matplotlib for plotting. If you are working in a Jupyter Notebook, don't forget to call the %matplotlib inline magic:
In [1]: import numpy as np
... import cv2
... import matplotlib.pyplot as plt
... %matplotlib inline
In [2]: plt.style.use('ggplot')
推薦閱讀
- Visual C++程序設計教程
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Mastering JavaScript Functional Programming
- Progressive Web Apps with React
- 數據結構(Java語言描述)
- 神經網絡編程實戰:Java語言實現(原書第2版)
- Python零基礎快樂學習之旅(K12實戰訓練)
- 數據結構習題精解(C語言實現+微課視頻)
- HTML5游戲開發案例教程
- Visual FoxPro程序設計
- BIM概論及Revit精講
- Access 2010數據庫應用技術(第2版)
- D3.js By Example
- JavaScript腳本特效編程給力起飛
- 時空數據建模及其應用