@ -4,7 +4,7 @@ K-Means Clustering in OpenCV {#tutorial_py_kmeans_opencv}
Goal
Goal
----
----
- Learn to use **cv2.kmeans()** function in OpenCV for data clustering
- Learn to use **cv.kmeans()** function in OpenCV for data clustering
Understanding Parameters
Understanding Parameters
------------------------
------------------------
@ -16,9 +16,9 @@ Understanding Parameters
-# **nclusters(K)** : Number of clusters required at end
-# **nclusters(K)** : Number of clusters required at end
-# **criteria** : It is the iteration termination criteria. When this criteria is satisfied, algorithm iteration stops. Actually, it should be a tuple of 3 parameters. They are \`( type, max_iter, epsilon )\`:
-# **criteria** : It is the iteration termination criteria. When this criteria is satisfied, algorithm iteration stops. Actually, it should be a tuple of 3 parameters. They are \`( type, max_iter, epsilon )\`:
-# type of termination criteria. It has 3 flags as below:
-# type of termination criteria. It has 3 flags as below:
- **cv2.TERM_CRITERIA_EPS** - stop the algorithm iteration if specified accuracy, *epsilon*, is reached.
- **cv.TERM_CRITERIA_EPS** - stop the algorithm iteration if specified accuracy, *epsilon*, is reached.
- **cv2.TERM_CRITERIA_MAX_ITER** - stop the algorithm after the specified number of iterations, *max_iter*.
- **cv.TERM_CRITERIA_MAX_ITER** - stop the algorithm after the specified number of iterations, *max_iter*.
- **cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER** - stop the iteration when any of the above condition is met.
- **cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER** - stop the iteration when any of the above condition is met.
-# max_iter - An integer specifying maximum number of iterations.
-# max_iter - An integer specifying maximum number of iterations.
-# epsilon - Required accuracy
-# epsilon - Required accuracy
@ -26,7 +26,7 @@ Understanding Parameters
initial labellings. The algorithm returns the labels that yield the best compactness. This
initial labellings. The algorithm returns the labels that yield the best compactness. This
compactness is returned as output.
compactness is returned as output.
-# **flags** : This flag is used to specify how initial centers are taken. Normally two flags are
-# **flags** : This flag is used to specify how initial centers are taken. Normally two flags are
used for this : **cv2.KMEANS_PP_CENTERS** and **cv2.KMEANS_RANDOM_CENTERS**.
used for this : **cv.KMEANS_PP_CENTERS** and **cv.KMEANS_RANDOM_CENTERS**.
### Output parameters
### Output parameters
@ -47,7 +47,7 @@ t-shirt problem where you use only height of people to decide the size of t-shir
So we start by creating data and plot it in Matplotlib
So we start by creating data and plot it in Matplotlib
@code{.py}
@code{.py}
import numpy as np
import numpy as np
import cv2
import cv2 as cv
from matplotlib import pyplot as plt
from matplotlib import pyplot as plt
x = np.random.randint(25,100,25)
x = np.random.randint(25,100,25)
@ -70,13 +70,13 @@ that, whenever 10 iterations of algorithm is ran, or an accuracy of epsilon = 1.