0

我在该相机上使用 micropython 运行我的代码:OpenMV Camera

我在python中随机得到了self未定义的错误。这就是我的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 条不同的错误消息:

有时在 self.findBlobs() 或“self.possibleLandmarkIDs = []”中

AttributeError: ',' 对象没有属性 'possibleLandmarkIDs'

有时','是'int'或'(箭头符号)',这可能是因为计算机和相机之间的通信中断。

另一种类型的错误是在 print(type(self)),“local variable self was called before defined”是错误消息。调用函数时从未发生此错误,它始终在函数内。

这些错误完全随机发生。这个方法被调用了几百次,突然就不行了?而且由于此类的实例不在任何特定范围内(它的创建就像您打开解释器并键入 >>> a = 0),我无法想象它被垃圾收集器删除了。

有谁知道它可能是什么,或者我可以继续研究吗?谢天谢地,期待您的回答,desireentz

编辑:

这里我添加了 findBlobs(self) 函数:

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()
4

1 回答 1

2

Since I, at first, thought that this was a general (micro-)python error, I created this topic here. Then I posted the same question at the official forum of the OpenMV camera and uploaded the whole file. One of the developers of the firmware answered me that this implementation of micropython had no stack protection because that would cost a lot of performance. And I was using a recursive function which then corrupted the heap when the stack was full, producing these "random" errors.

于 2017-06-26T06:55:12.793 回答