# 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字典语法的方法
https://forum.singtown.com/topic/3607/%E5%A6%82%E4%BD%95%E8%AF%86%E5%88%AB%E6%9C%80%E5%A4%A7%E7%9A%84%E8%89%B2%E5%9D%97-%E5%B9%B6%E8%BF%94%E5%9B%9E%E6%9C%80%E5%A4%A7%E8%89%B2%E5%9D%97%E7%9A%84%E9%A2%9C%E8%89%B2/3
OpenMV支持python标准的函数。