I have a final list like this, notice the "None" at the end and I am trying to reformat it:
[array([[[18, 10, 10],
[44, 38, 10]]], dtype=uint16), array([[[24, 32, 9]]], dtype=uint16), array([[[18, 12, 9]]], dtype=uint16), array([[[20, 34, 9]]], dtype=uint16), array([[[16, 12, 10]]], dtype=uint16), array([[[16, 12, 10]]], dtype=uint16), None]
This is what comes directly out of the function cv.HoughCircles():
[[[18.5 10.5 10.3]]]
If it failed to read it will return
"None"
This is the output from Hough circles in OpenCV. Occasionally Hough Circles will output a "None", I have a check in case it fails but it doesn't stop None being read.
I cannot get a check to work properly to stop the None from being appended or removed.
This is the Hough Circle Code:
def Hough_Circles(image,dp,minDist,param1,param2,minRadius,maxRadius):
try:
circles = cv.HoughCircles(image, cv.HOUGH_GRADIENT, dp, minDist,
param1=param1,
param2=param2,
minRadius=minRadius,
maxRadius=maxRadius)
if(circles == None):
#this is a keyword to keep it from appending later
circles = "REMOVE ME"
else:
circles = np.uint16(np.around(circles))
except:
print("no circle found")
return circles
I have tried the following methods to check and remove this:
this was tried after np.uint16()
if(circles[index] != None):
# this is a good item
if(any(circles == None))
# This is a bad item
this was tried before np.uint()
if(isinstance(circles,list):
# This is a good item
if(circles == None):
# this is a bad item
if(isinstance(circles,list)):
# it says [[[18.5 10.5 10.3]]] is not a list
circles = np.uint16(np.around(circles))
else:
# this is all it reads
circles = "BAD READ"
I've tried to remove it before the np.uint is added but does not help.
My issue is almost always "NoneType is not subscriptable" or "the truthvalue of a subscribable is ambiguous" which makes sense. But also the "isinstance" always says that the list is not a list, however, the same test on a python console says it is a list.