2017-06-13 77 views
-1

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

您缺少'__init __(self)'函數。 –

+0

你可以發佈'def findBlobs'嗎? – salparadise

+0

存在'__init __(self)'功能。 – desireentz

回答

1

自從我,起初,以爲這是一個普通(微 - )python錯誤,我在這裏創建了這個話題。然後,我在OpenMV相機的官方論壇上發佈了相同的問題,並上傳了整個文件。其中一位固件開發人員回答說,這個micropython的實現沒有堆棧保護,因爲這會花費很多性能。而且我使用了一個遞歸函數,當堆棧已滿時會損壞堆,產生這些「隨機」錯誤。