import sensor, image, time, sys
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
#sensor.set_auto_exposure(False, 500)#这里设置曝光时间
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 = [(100, 0, -32, 6, -128, 127), # 红色
(58, 100, -2, 127, -11, 21),# 绿色
(100, 9, -49, 19, 12, 67)] # 蓝色
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['B']=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_dict, key=Max_dict.get() #出错 未解决
print(Max_dict)
print(max(Max_dict, key=lambda k: Max_dict[k]))我已经关闭了白平衡之类的东西了。我下面垫的是纯正的A4白纸,很明显偏红!
你可以直接运行hello world。
@kidswong999 恩恩,运行了,这样没解决呀:thinking_face:
那我建议你联系卖家,维修。