我正在我的代码与相机micropython:OpenMV Camera的Python:自随机没有定义
我随机得到的python错误,自我没有定义。这是我的Python代码看起来像:(整个文件就太长了)
class BlobAnalyser:
#
#constructor and lots of functions
#...
#
def findLandmarkCombo(self, bnoAngle, playingTowardsBlue):
self.findBlobs()
print(type(self))
self.possibleLandmarkIDs = []
if len(self.blobs) == 0:
return None
for blobIndex in range(len(self.blobs)):
self.possibleLandmarkIDs.append([])
#and so on and so on
现在,我有2个不同的错误信息:
sometimes within self.findBlobs() or at "self.possibleLandmarkIDs = []"
AttributeError: ',' object has no attribute 'possibleLandmarkIDs'
有时“”是'int'或'(箭头符号)',这可能是因为计算机和相机之间的通信中断。
其他类型的错误是在print(type(self)),“本地变量self被定义之前调用”是错误消息。调用该函数时此错误从未发生,它始终在该函数内。
这些错误完全随机发生。这种方法被称为几百次,突然它不起作用?由于这个类的实例不在任何特定的范围内(它的创建就像打开解释器并键入>>> a = 0),我无法想象它被垃圾收集器删除。
有没有人知道它可能是或者我可以继续研究? 值得庆幸的期待您的回答, desireentz
编辑:
在这里,我添加了findBlobs(个体经营)功能:
def findBlobs(self):
img = sensor.snapshot()
#merge = True,
allBlobs = img.find_blobs(self.thresholds, pixels_threshold=200, area_threshold=150, merge=True)
self.blobs = []
print("=====")
i = 0
for blob in allBlobs:
i += 1
img.draw_string(blob.cx() - 5, blob.cy() - 5, str(i))
img.draw_rectangle(blob.rect())
self.blobs.append(blob)
print(str(i) + ": " + str(bin(blob.code())))
self.sortBlobs()
您缺少'__init __(self)'函数。 –
你可以发布'def findBlobs'吗? – salparadise
存在'__init __(self)'功能。 – desireentz