用户在使用OpenMV4 H7进行圆环识别时遇到了内存错误问题。
import sensor, image, time, pyb
# 初始化摄像头
sensor.reset()#重置相机。
sensor.set_pixformat(sensor.GRAYSCALE) # 直接设置为灰度格式
sensor.set_framesize(sensor.QVGA)#设置图像分辨率(QVGA,320x240)。
sensor.skip_frames(time=2000)#跳过前2秒的帧,让相机稳定下来。
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8) # 拍摄一张照片。对拍摄的图像进行镜头畸变校正,参数1.8是畸变校正系数。
filtered_img = img.gaussian(3) # 对拍摄的灰度图像进行高斯滤波,参数3是滤波器的半径,用于平滑图像,减少噪声。
# 检测图像中的圆形
circles = filtered_img.find_circles(threshold=2300, x_margin=100, y_margin=100, r_margin=1, r_min=37, r_max=38, r_step=1)
#使用find_circles方法检测图像中的圆形:
#threshold=2300:圆形检测的阈值,用于区分圆形和背景。
#x_margin=100 和 y_margin=100:在检测到的圆形周围允许的误差范围。
#r_margin=1:半径的误差范围。
#r_min=37 和 r_max=38:检测的圆形半径范围。
#r_step=1:半径的搜索步长。
if circles:
c = circles[0]
filtered_img.draw_circle(c.x(), c.y(), c.r(), color=(0, 0, 0))
filtered_img.draw_cross(c.x(), c.y(), color=(0, 0, 0))
print("Circle at: ({0}, {1}) with radius {2}".format(c.x(), c.y(), c.r()))
# 将检测到的坐标发送
circle_data = "Circle at: ({0}, {1}) with radius {2}\r\n".format(c.x(), c.y(), c.r())

问题分析:代码中使用了高斯滤波和圆形检测算法,可能在处理过程中消耗了过多的内存资源,导致帧缓冲区内存不足。
删除帖子
减少算法或者降低分辨率运行