logo

现在是一识别到物体,这边就报错,应该是之前我把u盘main文件换成我的了,请问怎么解决?

2024-05-15 15:16
7
fi2e
import sensor, image, time ,pyb
from pyb import LED
from pyb import UART
import struct

import json
red_led   = LED(1)
green_led   = LED(2)
thresholds = [(25, 95, 23, 92, 10, 79), # 一般情况下的红色阈值
              (47, 99, -92, -18, 4, 84), # 一般情况下的绿色阈值(16, 40, -58, -18, 8, 50)
              (0, 80, -78, -20, -57, 4), # 一般情况下的蓝色阈值(26, 71, -27, 1, -59, -20)(7, 32, -31, 26, -82, -12)
              (0, 73, 94, 19, 1, 127)]
#red_threshold  = (12, 100, 127, 28, -128, 127)
#thresholds=[ (47, 99, -92, -18, 4, 84)]
#blue_threshold  = (12, 100, 127, 28, -128, 127)
#green_threshold  = (12, 100, 127, 28, -128, 127)
Left_Right_error=0
uart = UART(3, 256000)
middle = 0
distance = 0
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)
clock = time.clock()
def find_max(blobs):
    max_size=0
    for blob in blobs:
        if blob[2]*blob[3] > max_size:
            max_blob=blob
            max_size = blob[2]*blob[3]
    return max_blob

while(True):
    clock.tick()
    img = sensor.snapshot()
    blobs = img.find_blobs(thresholds)
 #   blobs = img.find_blobs(thresholds, pixels_threshold=150, area_threshold=150, merge=True)

    if blobs:
        green_led.on()
        max_blob = find_max(blobs)
        middle_x = max_blob.cx()
        middle_y = max_blob.cy()
        Len=max_blob[2]
        width=max_blob[3]
        img.draw_rectangle(max_blob.rect())
        img.draw_cross(max_blob.cx(), max_blob.cy())
        Lm = (max_blob[2]+max_blob[3])/2
        distance = int(2668/Lm)
       # print(distance)
        uart.writechar(0xf1)
        uart.writechar(middle_x>>8)
        uart.writechar(middle_x)
        uart.writechar(middle_y>>8)
        uart.writechar(middle_y)
        uart.writechar(Len>>8)
        uart.writechar(Len)
        uart.writechar(width>>8)
        uart.writechar(width)
        uart.writechar(0xf2)
        print(middle_x,middle_y,max_blob[2],max_blob[3])
    else:
        green_led.off()

for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10,
        r_min = 2, r_max = 100, r_step = 2):
    img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
    print(c)
image
2024-05-16 18:24
I
网红小智智 星瞳科技

1,你的代码最后缩进有错误

2,find_circles很耗费ram,所以OpenMV4 H7上不能在QVGA上使用

解决办法:

1,QVGA改为QQVGA

2,换OpenMV4 Plus