用户在使用 OpenMV 的 img.find_blobs() 函数后,尝试遍历返回的每个 blob 对象的质心坐标(cx/cy),但代码报错:TypeError: 'blob' object isn't iterable。错误出现在嵌套 for 循环中:for b in blobs:,而 blobs 本身已是单个 blob 实例,不可迭代。
for blobs in img.find_blobs([thresholds[2]], x_stride=4, y_stride=4, area_threshold=20, pixels_threshold=20):
img.draw_rectangle(blobs.rect())
img.draw_cross(blobs.cx(), blobs.cy())
if blobs:
for b in blobs:
print("Blob cx:", b.cx(), "Blob cy:", b.cy())blobs = img.find_blobs([thresholds[2]], x_stride=4, y_stride=4, area_threshold=20, pixels_threshold=20)
for blob in blobs: # ✅ 正确命名变量,避免歧义
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print("Blob cx:", blob.cx(), "Blob cy:", blob.cy())语法错误,建议参考IDE左上角:文件-示例中的代码