- 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')
推薦閱讀
- 黑客攻防從入門到精通(實(shí)戰(zhàn)秘笈版)
- Rust實(shí)戰(zhàn)
- Reactive Programming With Java 9
- 劍指Java:核心原理與應(yīng)用實(shí)踐
- Protocol-Oriented Programming with Swift
- 劍指大數(shù)據(jù):企業(yè)級(jí)數(shù)據(jù)倉(cāng)庫(kù)項(xiàng)目實(shí)戰(zhàn)(在線教育版)
- D3.js By Example
- Julia數(shù)據(jù)科學(xué)應(yīng)用
- 從零開始學(xué)Selenium自動(dòng)化測(cè)試:基于Python:視頻教學(xué)版
- Practical Predictive Analytics
- 物聯(lián)網(wǎng)系統(tǒng)架構(gòu)設(shè)計(jì)與邊緣計(jì)算(原書第2版)
- Python物理建模初學(xué)者指南(第2版)
- Hands-On ROS for Robotics Programming
- Linux Networking Cookbook
- Python程序設(shè)計(jì)現(xiàn)代方法