- 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')
推薦閱讀
- Java程序設計(慕課版)
- C語言程序設計(第3版)
- Power Up Your PowToon Studio Project
- Python 深度學習
- Learning SAP Analytics Cloud
- Cassandra Design Patterns(Second Edition)
- Julia機器學習核心編程:人人可用的高性能科學計算
- 基于差分進化的優化方法及應用
- 批調度與網絡問題的組合算法
- 深入分析GCC
- Modernizing Legacy Applications in PHP
- C語言程序設計
- Drupal 8 Development Cookbook(Second Edition)
- MongoDB Administrator’s Guide
- Java 11 and 12:New Features