python字典语法中的有些方法用不了的问题?
-
# Untitled - By: TREE - 周三 7月 24 2019 import sensor, image, time, sys sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) Max_dict={'R':0,'G':0,'B':0} def find_max(blobs): max_size=0 for blob in blobs: if blob.pixels() > max_size: max_blob=blob max_size = blob.pixels() return max_blob thresholds = [(27, 67, 19, 91, 45, 76), # 红色 (58, 100, -2, 127, -11, 21),# 绿色 (0, 30, -20, 30, -40, 50)] # 蓝色 threshold = [50, 50, 0, 0, 0, 0] # Middle L, A, B values. clock = time.clock() Curr_number=0 while(Curr_number<20): # clock.tick() img = sensor.snapshot() for i in range(3): blobs = img.find_blobs([thresholds[i]], pixels_threshold=30, area_threshold=30, merge=True) if blobs: max_blob_sum=find_max(blobs).pixels() if i==0: Max_dict['R']=max_blob_sum elif i==1: Max_dict['G']=max_blob_sum elif i==2: Max_dict['G']=max_blob_sum for blob in blobs: if blob.code(): img.draw_cross(blob.cx(), blob.cy()) img.draw_rectangle(blob.rect()) Curr_number+=1 # print(clock.fps()) max(Max_dict, key=Max_dict.get())
我想把找到的最大色块的面积放在字典中,然后比较大小,最后得出最大的面积的颜色的键值。
问题在于openmv好像没有字典语法的一些函数或者方法,是因为没import某些库吗?
get方法知识lcd库的,不是python字典语法的方法
-
-
OpenMV支持python标准的函数。