Micopython视觉识别
应用介绍
Micopython视觉识别
pyb中定义io,输出高低电平,采用二进制编码,下位机读取对应的引脚电平,执行函数
OpenMv与Arduino串口通信,会出现乱码,不稳定的现象。
import sensor, image, time, pyb, math
#from pyb import UART
p1 = pyb.Pin("P1", pyb.Pin.OUT_PP)
p2 = pyb.Pin("P2", pyb.Pin.OUT_PP)
p3 = pyb.Pin("P3", pyb.Pin.OUT_PP)
p4 = pyb.Pin("P4", pyb.Pin.OUT_PP)
red_threshold = (30, 86, 28, 97, -47, 92)
green_threshold = (45, 97, -88, -25, -69, 96)
blue_threshold = (74, 90, -29, 5, -59, -4)
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
clock = time.clock()
#uart = UART(3,9600)
def find_max(blobs):
max_size=0
for blob in blobs:
if blob[2]*blob[3] > max_size:
max_blob=blob
max_size = blob[2]*blob[3]
return max_blob
def find_maxsize(size1,size2,size3):
if size1>size2:
if size1>size3:
return 1
else :
return 3
else :
if size2>size3:
return 2
elif size3>size2 :
return 3
size11=0
size21=0
size31=0
while(True):
clock.tick()
img = sensor.snapshot()
#lens_corr(1.8)畸变矫正
blob1=img.find_blobs([red_threshold], pixels_threshold=700, area_threshold=700,merge=True)
if blob1:
max_blob1=find_max(blob1)
size11=max_blob1[2]*max_blob1[3]
blob2=img.find_blobs([green_threshold], pixels_threshold=700, area_threshold=700,merge=True)
if blob2:
max_blob2=find_max(blob2)
size21=max_blob2[2]*max_blob2[3]
blob3=img.find_blobs([blue_threshold], pixels_threshold=700, area_threshold=700,merge=True)
if blob3:
max_blob3=find_max(blob3)
size31=max_blob3[2]*max_blob3[3]
num=find_maxsize(size11,size21,size31)
if num==1:
img.draw_cross(max_blob1.cx(), max_blob1.cy(),color = (176,48,96))
p1.low()
p2.low()
p3.high()
print('1')
elif num==2:
img.draw_cross(max_blob2.cx(), max_blob2.cy(),color = (34,139,34))
p1.low()
p2.high()
p3.low()
print('2')
elif num==3:
img.draw_cross(max_blob3.cx(), max_blob3.cy(),color = (0,0,128))
p1.low()
p2.high()
p3.high()
print('3')
#uart.write('\n')
#print(clock.fps())
。。。。。。。想了解详情请下载附件
©版权声明:本文内容由互联网用户自发贡献,版权归原创作者所有,本站不拥有所有权,也不承担相关法律责任。如果您发现本站中有涉嫌抄袭的内容,欢迎发送邮件至: [email protected] 进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
转载请注明出处: apollocode » Micopython视觉识别
文件列表(部分)
名称 | 大小 | 修改日期 |
---|---|---|
0924.py | 0.72 KB | 2020-08-06 |
0928.py | 0.78 KB | 2020-08-06 |
takephoto.py | 0.48 KB | 2019-11-09 |
openmv | 0.00 KB | 2020-08-06 |
发表评论 取消回复