import sensor, image, time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QVGA for quailtiy ,use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False)
#关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
clock = time.clock() # Tracks FPS.
weed_threshold_01 = ((31, 100, -128, -12, 0, 127))
'''
扩宽roi
'''
def expand_roi(roi):
# set for QQVGA 160*120
extra = 5
win_size = (160, 120)
(x, y, width, height) = roi
new_roi = [x-extra, y-extra, width+2*extra, height+2*extra]
if new_roi[0] < 0:
new_roi[0] = 0
if new_roi[1] < 0:
new_roi[1] = 0
if new_roi[2] > win_size[0]:
new_roi[2] = win_size[0]
if new_roi[3] > win_size[1]:
new_roi[3] = win_size[1]
return tuple(new_roi)
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([weed_threshold_01], area_threshold=150)
if blobs:
#如果找到了目标颜色
# print(blobs)
for blob in blobs:
#迭代找到的目标颜色区域
is_rect = False
max_area = 0
new_roi = expand_roi(blob.rect())
rects=img.find_rects(roi=new_roi,threshold = 10000)
if rects:
is_rect=True
for rect in rects:
print(rects)
if rect.w()*rect.h() > max_area:
max_area = rect.w()*rect.h()
max_circle = rect
img.draw_rectangle(max_circle.x(),max_circle.y(),max_circle.w(),max_circle.h())
print(clock.fps())
我使用OpenMV4测试这个代码,没有出现错误。
请提供一下出现错误的方法。

小智智,我是在EDGR IMPULSE 导入神经网络出现这个错误,使用型号是OPENMV4 H7 CAM(不是PLUS),可以解决吗这个报错
:confounded_face:

@bhkl edge impulse的模型只能在OpenmV4 Plus上用,OpenMV4不行。
@kidswong999 好,谢谢您