- 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')
推薦閱讀
- scikit-learn Cookbook
- Mastering Entity Framework Core 2.0
- Visual FoxPro程序設計教程
- Java EE框架整合開發入門到實戰:Spring+Spring MVC+MyBatis(微課版)
- PowerCLI Cookbook
- 深入實踐Spring Boot
- Unity Shader入門精要
- Python圖形化編程(微課版)
- Visual Studio 2015高級編程(第6版)
- JavaScript動態網頁編程
- 人工智能算法(卷1):基礎算法
- Learning Ionic
- Java 從入門到項目實踐(超值版)
- Hacking Android
- C語言程序設計