![0_1565403972392_pink.bmp](正在上传 100%)
![0_1565404272650_pink2.bmp](正在上传 100%)
为什么在摄像头捕捉到的画面中 两张颜色的鲜艳度差的这么多
代码没更改过 期间只更换过小球
摄像头开一段时间之后颜色就变得鲜艳 重新启动后又变得暗淡
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
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
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8)
for c in img.find_circles(threshold = 1050, x_margin = 10, y_margin = 10, r_margin = 40,
r_min = 50, r_max = 200, r_step = 10):
area = (c.x()-c.r(), c.y()-c.r(), c.r(), c.r())
#img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的红色圆形用红色的圆框出来
#area为识别到的圆的区域,即圆的外接矩形框
statistics = img.get_statistics(roi=area)#像素颜色统计
print(statistics)
#(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。
#l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
if 0<statistics.l_min()<10 and 10<statistics.a_mode()<30 and -20<statistics.b_mode()<5:#if the circle is pink
img.draw_circle(c.x(), c.y(), c.r(), color = (255,0,255))#识别到的粉色圆形用红色的圆框出来
elif 0<statistics.l_min()<20 and -5<statistics.a_mode()<5 and -2<statistics.b_mode()<2:#if the circle is white
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 255))#识别到的白色圆形用白色的圆框出来
elif 0<statistics.l_mode()<20 and -20<statistics.a_mode()<40 and -60<statistics.b_mode()<35:#if the circle is white
img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 255))#识别到的白色圆形用白色的圆框出来
#print("FPS %f" % clock.fps())