我正在我的代碼與相機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