logo

选择兴趣区然后大概率会报错 是什么原因啊报错内容如下

2023-07-19 11:25
X
fc3i

:RuntimeError:Frame size is not supported or is not set

2023-07-19 20:21
I
网红小智智 星瞳科技

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片

2023-07-20 10:41
X
fc3i
THRESHOLD =(79, 93, -24, 16, -19, 22)
THRESHOLD1 =(77, 94, -22, 18, -15, 17)
THRESHOLDG = (56, 78, -31, 1, -19, 25)
THRESHOLDB = (43, 71, -10, 20, -52, -9)
THRESHOLDR = (38, 67, 5, 41, -26, 24)
GRAYSCALE_THRESHOLD = (240, 255)
GRAYSCALE_THRESHOLD1 = (117, 86)
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
xingzhuang=0
import sensor, image, time,json,pyb,math,cpufreq
from pyb import LED,UART,Pin,Timer
from image import SEARCH_EX, SEARCH_DS
roi_x=0
roi_y=0
roi_w=0
roi_h=0
uart = UART(3, 9600,timeout_char = 0)
sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.FHD)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 1900)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.
sensor.set_vflip(True)
sensor.set_hmirror(True)
img = sensor.snapshot()
#pyb.delay(600)
blobs = img.find_blobs([THRESHOLD],pixels_threshold=200000, area_threshold=5000,merge=False)                               # to the IDE. The FPS should increase once disconnected.
if blobs:
        img.draw_rectangle(blobs[0].rect(),color=(0,0,255))
        img.draw_cross(blobs[0].cx(),blobs[0].cy(),color=(0,0,255))
        a=blobs[0].x()+8
        b=blobs[0].y()+8
        c=blobs[0].w()-20
        d=blobs[0].h()-28
        print('白色',a,b,c,d)
        sensor.set_windowing((a,b,c,d))
#sensor.set_windowing((206,103,180,240)) #取中间的640*80区域
#print('cpu:',cpufreq.get_current_frequencies())

while(True):
    clock.tick()
    #pyb.delay(900)
    img = sensor.snapshot()
    print(clock.fps())
    sum = 0
    for l in img.find_line_segments(merge_distance = 250, max_theta_diff = 20):
        #area = (l.x1(),l.y2(),l.x2()-l.x1(),l.y2()-l.y1())
        #statistics = img.get_statistics(roi=area)
        #img.draw_line(l.line(),color = (255,0,0))
        #img.draw_cross(l.x1(),l.y1(),color=(255,0,0))
        #img.draw_cross(l.x2(),l.y2(),color=(255,0,0))
        sum += l.theta()
    sum-=90
    print(sum)
    if sum < 200 and sum >160:
        print('三角形')
        xingzhuang=1
    if sum >70 and sum <120:
        print('正方形')
        xingzhuang=2
    if sum >380:
        print('圆形')
        xingzhuang=3
    roi_x=0
    roi_y=0
    roi_w=0
    roi_h=0
    yanse=0
    blobs = img.find_blobs([THRESHOLDB],pixels_threshold=1000, area_threshold=600,merge=False)                               # to the IDE. The FPS should increase once disconnected.
    if blobs:
        img.draw_rectangle(blobs[0].rect(),color=(0,0,255))
        #img.draw_cross(blobs[0].cx(),blobs[0].cy(),color=(0,0,255))
        print('蓝色')
        roi_x=blobs[0].x()
        roi_y=blobs[0].y()
        roi_w=blobs[0].w()
        roi_h=blobs[0].h()
        yanse=1
        m=blobs[0].pixels()
        print('像素数:',m)
        #img.binary([THRESHOLDB],invert=True)
        #img.erode(3)
        #img.dilate(4)
        pyb.delay(6)
    blobs = img.find_blobs([THRESHOLDR],pixels_threshold=200, area_threshold=20,merge=False)                               # to the IDE. The FPS should increase once disconnected.
    if blobs:
        #img.draw_rectangle(blobs[0].rect(),color=(255,0,0))
        #img.draw_cross(blobs[0].cx(),blobs[0].cy(),color=(255,0,0))
        print('红色')
        roi_x=blobs[0].x()
        roi_y=blobs[0].y()
        roi_w=blobs[0].w()
        roi_h=blobs[0].h()
        yanse=2
        m=blobs[0].pixels()
        print('像素数:',m)
        pyb.delay(6)
    blobs = img.find_blobs([THRESHOLDG],pixels_threshold=2000, area_threshold=200,merge=False)                               # to the IDE. The FPS should increase once disconnected.
    if blobs:
        #img.draw_rectangle(blobs[0].rect(),color=(0,255,0))
        #img.draw_cross(blobs[0].cx(),blobs[0].cy(),color=(0,255,0))
        roi_x=blobs[0].x()
        roi_y=blobs[0].y()
        roi_w=blobs[0].w()
        roi_h=blobs[0].h()
        print('绿色')
        yanse=3
        #img.binary([THRESHOLDG],invert=True)
        m=blobs[0].pixels()
        print('像素数:',m)
        pyb.delay(6)
    if xingzhuang==3:
        blobs = img.find_blobs([THRESHOLD1],pixels_threshold=20000, area_threshold=2000,roi=(roi_x,roi_y,roi_w,roi_h),merge=False)                               # to the IDE. The FPS should increase once disconnected.
        if blobs:
             img.draw_rectangle(blobs[0].rect(),color=(255,255,255))
             img.draw_cross(blobs[0].cx(),blobs[0].cy(),color=(255,255,255))
             kuandu=(roi_w-blobs[0].w())/2*(210/(c+20))
             print('宽度:',kuandu,'mm')
             juli=math.sqrt(pow(blobs[0].cx(),2)+pow(blobs[0].cy(),2))*(210/(c-10))
             print('圆心距离左上角:',juli,'mm')
             pyb.delay(6)
    if xingzhuang==2:
        blobs = img.find_blobs([THRESHOLD1],pixels_threshold=20000, area_threshold=2000,roi=(roi_x,roi_y,roi_w,roi_h),merge=False)                               # to the IDE. The FPS should increase once disconnected.
        if blobs:
             img.draw_rectangle(blobs[0].rect(),color=(255,255,255))
             img.draw_cross(blobs[0].cx(),blobs[0].cy(),color=(255,255,255))
             kuandu=(roi_w-blobs[0].w())/2*(210/(c+20))
             gaodu=(roi_h-blobs[0].h())/2*(210/(c+20))
             xiankuan=(kuandu+gaodu)/2
             kuandu1=(roi_w+blobs[0].w())/2*(210/(c+20))
             gaodu1=(roi_h+blobs[0].h())/2*(210/(c+20))
             print('宽度:',kuandu1,'mm')
             print('高度:',gaodu1,'mm')
             data=[]
             data.append((xingzhuang,yanse,int(xiankuan),int(kuandu1),int(gaodu1),0))
             data_out = json.dumps(set(data))
             uart.write(data_out +'\n')
             print('you send:',data_out)
             pyb.delay(6)
    if xingzhuang==1:
        cishu=0
        zhouchang=0
        xianchang=[0,0,0,0,0,0,0,0]
        for l in img.find_line_segments(merge_distance = 20000, max_theta_diff = 20):
            img.draw_line(l.line(),color = (255,0,0))
            changdu=l.length()*(210/(c-25))
            print('长度',cishu,':',changdu)
            xianchang[cishu]=changdu
            cishu=cishu+1
            zhouchang=changdu+zhouchang
        if cishu==3:
            print('周长:',zhouchang)
            xiankuan=(m*((210/(c-20))*(210/(c-20))))/zhouchang
            print('线宽:',xiankuan)
            data=[]
            #data.append((xingzhuang,yanse,int(zhouchang),int(xiankuan)))
            data.append((xingzhuang,yanse,int(xiankuan),int(xianchang[0]),int(xianchang[1]),int(xianchang[2])))
            data_out = json.dumps(set(data))
            uart.write(data_out +'\n')
            print('you send:',data_out)
        pyb.delay(6)
    xingzhuang=0
    m=0
X
fc3i

全部代码文本如下

2023-07-20 17:45
I
网红小智智 星瞳科技

使用的什么硬件?是OpenMV4 Plus吗?

2023-07-20 18:34
X
fc3i

@kidswong999 在 [选择兴趣区然后大概率会报错 是什么原因啊报错内容如下](/post/29495) 中说:

> 是OpenMV4 h7 Plus

2023-07-22 14:13
I
网红小智智 星瞳科技

我使用官方的板子,OpenMV4 H7 Plus,sensor OV5640,不是你这个报错。你确定你用的是官方的板子?

2023-07-30 21:31
X
fc3i

@kidswong999 是啊 在你们淘宝店铺买了俩块顶配

2023-07-31 17:26
I
网红小智智 星瞳科技

@fc3i 那我建议你寄回检查一下。