- fixed runtime errors if no objects are present
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@321 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+6
-2
@@ -62,7 +62,7 @@ class FindObjects():
|
|||||||
temp_objects = []
|
temp_objects = []
|
||||||
objectsCandIds = []
|
objectsCandIds = []
|
||||||
|
|
||||||
if hierachy.any():
|
if hierachy is not None:
|
||||||
while count != -1:
|
while count != -1:
|
||||||
family = FindObjects.getFamily([], count, hierachy)
|
family = FindObjects.getFamily([], count, hierachy)
|
||||||
|
|
||||||
@@ -294,6 +294,8 @@ if videoFile == "piCamera":
|
|||||||
print("[INFO] Camera : elasped time: {:.2f}".format(vs.getfps().elapsed()))
|
print("[INFO] Camera : elasped time: {:.2f}".format(vs.getfps().elapsed()))
|
||||||
print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
||||||
|
|
||||||
|
if numColorClasses:
|
||||||
|
|
||||||
# Output stats
|
# Output stats
|
||||||
findObjects.printStats()
|
findObjects.printStats()
|
||||||
|
|
||||||
@@ -316,7 +318,7 @@ Z = np.float32(plotColors)
|
|||||||
|
|
||||||
# Define criteria = ( type, max_iter, epsilon )
|
# Define criteria = ( type, max_iter, epsilon )
|
||||||
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1)
|
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1)
|
||||||
ret,label,center=cv2.kmeans(Z,numColorClasses,None,criteria,10,cv2.KMEANS_PP_CENTERS)
|
ret,label,center=cv2.kmeans(np.float32(plotColors), numColorClasses, None, criteria, 10, cv2.KMEANS_PP_CENTERS)
|
||||||
|
|
||||||
print (center)
|
print (center)
|
||||||
|
|
||||||
@@ -339,6 +341,8 @@ ax.scatter(center[:,2], center[:,1], center[:,0], zdir='z', s=500, facecolors=ce
|
|||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Sorry, no colors have been detected")
|
||||||
|
|
||||||
# do a bit of cleanup
|
# do a bit of cleanup
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|||||||
Reference in New Issue
Block a user