Arena size is too small for all buffers.
-
Arena size is too small for all buffers. Needed 225840 but only 189856 was available. AllocateTensors() failed!
# Untitled - By: Administrator - 周五 7月 14 2023 import sensor, image, time, os, tf, math, uos, gc ,ustruct ,pyb from pyb import UART ,LED ,Timer uart = UART(3,115200) #定义串口3变量 uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQQVGA) sensor.skip_frames(time = 2000) sensor.set_vflip(True) sensor.set_hmirror(True)#水平镜像 clock = time.clock() global r_flag r_flag = 1 def outuart(x,a,flag): global uart f_x=0 f_a=0 if flag==1: #十字 x,a,f_x,f_a=(0,0,0,1) if flag==2: #上左 x,a,f_x,f_a=(0,0,1,0) if flag==3: #上右 x,a,f_x,f_a=(0,0,1,1) if flag==4: #stop x,a,f_x,f_a=(1,1,1,2) data = ustruct.pack("<bbhhhhb", #格式为俩个字符俩个短整型(2字节) 0x2C, #帧头1 0x12, #帧头2 int(x), # up sample by 4 #数据1 int(a), # up sample by 4 #数据2 int(f_x), # up sample by 4 #数据1 int(f_a), # up sample by 4 #数据2 0x5B) if flag!=1: uart.write(data) #必须要传入一个字节数组 else: uart.write(data) #必须要传入一个字节数组 time.sleep_ms(1) def findline(): global r_flag THRESHOLD = (18, 61, 14, 89, -2, 63) LED(1).on() LED(2).on() LED(3).on() sensor.set_framesize(sensor.QQQVGA) roi1 = [(0,17,15,25),#左 (65,17,15,25),#右 (30,0,20,15)]#上 img = sensor.snapshot().binary([THRESHOLD]) line = img.get_regression([(100,100)], robust = True) left_flag,right_flag,up_flag=(0,0,0) for rec in roi1: img.draw_rectangle(rec, color=(255,0,0))#绘制出roi区域 if (line): rho_err = abs(line.rho())-img.width()/2 if line.theta()>90: theta_err = line.theta()-180 else: theta_err = line.theta() img.draw_line(line.line(), color = 127) if line.magnitude()>8:#if -40<b_err<40 and -30<t_err<30: outdata=[rho_err,theta_err,0] print(outdata) outuart(rho_err,theta_err,0) if img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[0]): #left #print('left') left_flag=1 if img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[1]): #right #print('right') right_flag=1 if img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[2]): #up #print('up') up_flag=1 if left_flag==1 and right_flag==1: outuart(0,0,1) #time.sleep_ms(5) print('shizi') if left_flag==1 and up_flag==1: outuart(0,0,2) print('up-left') if right_flag==1 and up_flag==1: outuart(0,0,3) print('up-right') else: outuart(0,0,4) print('stop') global x,y,target,t_flag,middle_x middle_x = 120 flag=0 target = 0 t_flag = 0 def FirstFindNum(Finded_Num): global target,t_flag,uart if t_flag == 0 and Finded_Num>0: target = Finded_Num t_flag = 1 print('+++++++++++++++++++++++++已经识别到数字+++++++++++++++++++++++++++++++++++') data = ustruct.pack("<bbhb", #格式为俩个字符俩个短整型(2字节) 0x2C, #帧头1 0x12, #帧头2 int(t_flag), # up sample by 4 #数据1识别到目标的标识符 0x5B) uart.write(data) return target global s_flag s_flag = 0 def FindNum(x,y,target,i): global s_flag,flag,uart,t_flag,x_flag if t_flag == 1 and target == i: s_flag+=1 x_flag = 0 if(s_flag == 20): print('//////////////////////////////发送一次标志位////////////////////////////////////////') s_flag = 0 x_flag = 1 if x>middle_x: flag=1 print(flag) else: flag=0 print(flag) if x_flag>0: data = ustruct.pack("<bbhhb", #格式为俩个字符俩个短整型(2字节) 0x2C, #帧头1 0x12, #帧头2 int(x_flag), # up sample by 4 #数据1识别到目标的标识符 int(flag), # up sample by 4 #数据2左右标识符 -1 是左 1是右 0x5B) uart.write(data) #必须要传入一个字节数组 def findnum(): sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) sensor.set_windowing((240, 240)) # Set 240x240 window. net = None labels = None min_confidence = 0.7 colors = [ # Add more colors if you are detecting more than 7 types of classes at once. (255, 0, 0), ( 0, 255, 0), (255, 255, 0), ( 0, 0, 255), (255, 0, 255), ( 0, 255, 255), (100, 255, 255), (255, 100, 255), (255, 255, 100), (255, 255, 255), ] #try: # load the model, alloc the model file on the heap if we have at least 64K free after loading net = tf.load("trained.tflite", load_to_fb=uos.stat('trained.tflite')[6] > (gc.mem_free() - (128*1024))) #except Exception as e: #raise Exception('Failed to load "trained.tflite", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')') #try: labels = [line.rstrip('\n') for line in open("labels.txt")] #except Exception as e: #raise Exception('Failed to load "labels.txt", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')') # detect() returns all objects found in the image (splitted out per class already) # we skip class index 0, as that is the background, and then draw circles of the center # of our objects data = net.detect(img, thresholds=[(math.ceil(min_confidence * 255), 255)]) for i, detection_list in enumerate(data): if (i == 0): continue # background class if (len(detection_list) == 0): continue # no detections for this class? print("********** %s **********" % labels[i]) for d in detection_list: global center_x,center_y if i==1: print('数字1',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==2: print('数字2',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==3: print('数字3',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==4: print('数字4',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==5: print('数字5',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==6: print('数字6',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==7: print('数字7',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) if i==8: print('数字8',d.output()) [x, y, w, h] = d.rect() center_x = math.floor(x + (w / 2)) center_y = math.floor(y + (h / 2)) print('x %d\ty %d' % (center_x, center_y)) #img.draw_cross((center_x, center_y), color=colors[i], size = 10, thickness=2) img.draw_string(center_x + 12, center_y + 12, labels[i], color=colors[i],scale=4) img.draw_rectangle(x-35,y-50, w+70, h+90, color =colors[i], thickness = 1, fill = False) #outuart(center_x,center_y,i) FirstFindNum(i) FindNum(center_x,center_y,target,i) clock = time.clock() while(True): clock.tick() img = sensor.snapshot() print(r_flag) global r_flag if uart.any(): a = uart.read(1).decode().strip() #uart.read()为一个字节串,加.decode() 变成字符串 r_flag = int(a) print(r_flag) if r_flag == 0: findline() elif r_flag == 1: findnum()
-
这个报错是因为什么问题
-
openmv h7 plus
-
先精简为直接运行就报错的代码。你的代码我没办法测试。