运行的时候返回的串口数据一直变化,想要一个固定的数据怎样实现?
你需要上传代码。
import sensor, image, time
Thresholds = [(40, 74, 74, 18, -31, 42), #修改后红色的阈值
(84, 94, -57, -22, -27, 40)] # 修改后的绿色的阈值
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) #使用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
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8)
ROI=(20,15,256,192)
#for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,
#r_min = 2, r_max = 100, r_step = 2):
for c in img.find_circles(roi=ROI,threshold = 6000, x_margin = 10, y_margin = 10,
r_margin = 10,r_min = 10, r_max = 30, r_step = 2): #修改后识别圆形的参数
area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
#area为识别到的圆的区域,即圆的外接矩形框
statistics = img.get_statistics(thresholds=Thresholds,roi=area) #像素颜色统计,
#print(statistics) #不输出颜色的参数
#(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。
#l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
if 0<statistics.l_mode()<100 and 0<statistics.a_mode()<74 and -31<statistics.b_mode()<42:#if the circle is red
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的红色圆形用红色的圆框出来
red_strs=[c[0],c[1],c[2]]
#for index in range(len(c)):
#print c[index]
#for red_str in red_strs:
#print ('red_str:',red_str)
print (red_strs)
print (c)
elif 30<statistics.l_mode()<100 and -64<statistics.a_mode()<-8 and -32<statistics.b_mode()<32: #识别绿色的圆
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的绿色圆形用红色的圆框出来
else: #识别红色或绿色
img.draw_rectangle(area, color = (255, 255, 255))
#将非红色的圆用白色的矩形框出来
#print("FPS %f" % clock.fps())你的程序就是每秒发送几十次串口数据。
@kidswong999 那我需要改什么参数吗?还是说我可以修改只读取它某一帧的参数吗
我不清楚你的目的是什么
@kidswong999 我想把检测到的圆心和半径传给Arduino,但是它每次发送这么多的数据,Arduino无法处理吧
能处理,数据量不多