- 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')
推薦閱讀
- UI圖標(biāo)創(chuàng)意設(shè)計(jì)
- Visual C++程序設(shè)計(jì)教程
- Oracle 11g從入門到精通(第2版) (軟件開發(fā)視頻大講堂)
- Spring Cloud Alibaba微服務(wù)架構(gòu)設(shè)計(jì)與開發(fā)實(shí)戰(zhàn)
- PHP 7底層設(shè)計(jì)與源碼實(shí)現(xiàn)
- Mastering Ember.js
- Python語言實(shí)用教程
- C++反匯編與逆向分析技術(shù)揭秘(第2版)
- Developing SSRS Reports for Dynamics AX
- Flutter之旅
- INSTANT Lift Web Applications How-to
- R High Performance Programming
- MATLAB語言及編程實(shí)踐:生物數(shù)學(xué)模型應(yīng)用
- OpenCL異構(gòu)并行計(jì)算:原理、機(jī)制與優(yōu)化實(shí)踐
- Modern R Programming Cookbook