你的担心是多余的
G
gumy
@gumy
0
声望
4
楼层
369
资料浏览
0
粉丝
0
关注
gumy 发布的帖子
-
RE: NameError: name 'format' isn't defined怎么解决啊?
@kidswong999 :你好,我在python编译器里都是直接使用format()函数的,请问在openmv里需要导入哪个库才能解决呢,之前在文档里找没找到
-
RE: NameError: name 'format' isn't defined怎么解决啊?
import sensor, image, time,math,pyb from pyb import UART,LED import json red_threshold = (16, 40, 21, 53, 47, 17) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(10) sensor.set_auto_whitebal(False) clock = time.clock() uart = UART(3,115200) uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters K=2554 def Tablefun(list): list_set = set(list) frequency_dict = {} for i in list_set: frequency_dict[i] = list.count(i) grade_mode = [] for key, value in frequency_dict.items(): if value == max(frequency_dict.values()): grade_mode.append(key) break return grade_mode while(True): Tab_distance=[] while(len(Tab_distance)<20): length=0 clock.tick() img = sensor.snapshot() blobs = img.find_blobs([red_threshold]) if len(blobs) == 1: b = blobs[0] img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy Lm = (b[2]+b[3])/2 length = K/Lm Tab_distance.append(int(length)) length = Tablefun(Tab_distance) # uart.writechar(int(length[0])) length = format(length[0],'0>3')+ "\r\n" uart.write(length) print(">>", length, "<<")