- added kmeans clustering
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@313 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+15
-2
@@ -195,7 +195,7 @@ print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
|||||||
# Output stats
|
# Output stats
|
||||||
findObjects.printStats()
|
findObjects.printStats()
|
||||||
|
|
||||||
# Scatter plot of colors
|
# Analyze colors
|
||||||
numObjects = len(beadColors);
|
numObjects = len(beadColors);
|
||||||
blue = np.zeros(numObjects)
|
blue = np.zeros(numObjects)
|
||||||
green = np.zeros(numObjects)
|
green = np.zeros(numObjects)
|
||||||
@@ -209,11 +209,24 @@ for color in beadColors:
|
|||||||
plotColors[i] = [red[i], green[i], blue[i]]
|
plotColors[i] = [red[i], green[i], blue[i]]
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# Kmeans create color classes
|
||||||
|
Z = np.float32(plotColors)
|
||||||
|
|
||||||
|
# Define criteria = ( type, max_iter, epsilon )
|
||||||
|
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1)
|
||||||
|
ret,label,center=cv2.kmeans(Z,10,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
|
||||||
|
|
||||||
|
print (center)
|
||||||
|
|
||||||
|
# Scatter plot of colors
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
ax = fig.add_subplot(111, projection='3d')
|
ax = fig.add_subplot(111, projection='3d')
|
||||||
ax.scatter(blue, green, red, zdir='z', s=50, facecolors=plotColors, lw = 0, depthshade=True)
|
ax.scatter(blue, green, red, zdir='z', s=10, c=(0,0,0), lw = 0, depthshade=True)
|
||||||
|
ax.scatter(center[:,2], center[:,1], center[:,0], zdir='z', s=250, facecolors=center, lw = 2, depthshade=True)
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
# do a bit of cleanup
|
# do a bit of cleanup
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user