机缘
- 实战项目中的经验分享
- 日常学习过程中的记录
- 通过文章进行技术交流
- 记录自己的学习过程
收获
学到了更多的知识,也有了一个平台去发泄自己的想法
日常
一直在考研途中,工创赛也结束了。
import sensor, image, time,pyb
import ustruct
from pyb import Pin
from pyb import UART
from pyb import LED
left=0
middle=0
right=0
red_threshold=(0, 69, 78, 53, 19, 121)#红色颜色阈值
green_threshold=(73, 11, -66, -34, 33, -20)#绿色颜色阈值(100, 9, -74, -23, 29, -128)
blue_threshold=(89, 39, -96, 44, -118, -42)#蓝色颜色阈值(7, 42, -4, 52, -89, 3)
flag_color=2
red_color_code=1
green_color_code=2
blue_color_code=4
black_color_code=8
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_whitebal(False)
sensor.set_auto_gain(False)
while(True):
if uart.any():
data=uart.readline()
print(data)
led1.on()
if (data==b'\xa1'):
at=0
while(at==0):
led2.on()
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((300, 300))
img = sensor.snapshot()
for code in img.find_qrcodes():
if(code.payload()=='红色蓝色'):
at=1
if(code.payload()=='蓝色红色'):
at=2
if(code.payload()=='红色绿色'):
at=3
if(code.payload()=='绿色红色'):
at=4
if(code.payload()=='蓝色绿色'):
at=5
if(code.payload()=='绿色蓝色'):
at=6
sending_data(at)
print(at)
led2.off()
flag_color=0
if(data==b'\xa2'):
sensor.set_framesize(sensor.QVGA)
sensor.set_auto_whitebal(False)
sensor.set_auto_gain(False)
zhong=0
#p_out.high()
led2.on()
led3.on()
while(zhong==0):
clock.tick()
img = sensor.snapshot()
img.draw_rectangle((20,110,70,64),color=(0x00,0x00,0x00))
img.draw_rectangle((114,110,70,64),color=(0x00,0x00,0x00))
img.draw_rectangle((215,110,78,64),color=(0x00,0x00,0x00))
blob_left=img.find_blobs([red_threshold,green_threshold,blue_threshold],area_threshold=200,merge=True,roi=(10,110,70,67))
blob_middle=img.find_blobs([red_threshold,green_threshold,blue_threshold],area_threshold=200,merge=True,roi=(114,110,70,64))
blob_right=img.find_blobs([red_threshold,green_threshold,blue_threshold],area_threshold=200,merge=True,roi=(215,110,70,66))
left=0
middle=0
right=0
if blob_left:
for blob in blob_left:
led3.on()
x=blob[0]
y=blob[1]
width=blob[2]
height=blob[3]
center_x=blob[5]
center_y=blob[6]
color_code =blob[8]
if color_code==red_color_code:
img.draw_string(x,y-10,"red",color=(0xFF,0x00,0x00))
left=1
elif color_code==green_color_code:
img.draw_string(x,y-10,"green",color=(0x00,0xFF,0x00))
left=2
elif color_code==blue_color_code:
img.draw_string(x,y-10,"blue",color=(0x00,0x00,0xFF))
left=3
else:
left=0
color=color_code
img.draw_rectangle([x,y,width,height])
img.draw_cross(center_x,center_y)
if blob_middle:
for blob in blob_middle:
x=blob[0]
y=blob[1]
width=blob[2]
height=blob[3]
center_x=blob[5]
center_y=blob[6]
color_code =blob[8]
if color_code==red_color_code:
img.draw_string(x,y-10,"red",color=(0xFF,0x00,0x00))
middle=1
elif color_code==green_color_code:
img.draw_string(x,y-10,"green",color=(0x00,0xFF,0x00))
middle=2
elif color_code==blue_color_code:
img.draw_string(x,y-10,"blue",color=(0x00,0x00,0xFF))
middle=3
else:
middle=0
color=color_code
img.draw_rectangle([x,y,width,height])
img.draw_cross(center_x,center_y)
if blob_right:
for blob in blob_right:
x=blob[0]
y=blob[1]
width=blob[2]
height=blob[3]
center_x=blob[5]
center_y=blob[6]
color_code =blob[8]
if color_code==red_color_code:
img.draw_string(x,y-10,"red",color=(0xFF,0x00,0x00))
right=1
elif color_code==green_color_code:
img.draw_string(x,y-10,"green",color=(0x00,0xFF,0x00))
right=2
elif color_code==blue_color_code:
img.draw_string(x,y-10,"blue",color=(0x00,0x00,0xFF))
right=3
else:
right=0
color=color_code
img.draw_rectangle([x,y,width,height])
img.draw_cross(center_x,center_y)
led2.off()
led3.off()
if left !=0 and middle !=0 and right !=0 and left != middle and middle != right and left != right :
led2.on()
if left ==1 and middle ==2 and right ==3 :
print("%d%d%d" % (left,middle,right))
colour1 = [left,middle,right]
sending_data1(colour1)
print(colour1)
break
憧憬
希望能上岸电子科大
Tips