本文共 1068 字,大约阅读时间需要 3 分钟。
单色块识别并框选
import sensor, image,time,lcd#摄像头初始化sensor.reset()sensor.set_pixformat(sensor.RGB565)sensor.set_framesize(sensor.QVGA)sensor.set_vflip(1) #后置拍摄模式sensor.skip_frames(10) # Let new settings take affect.sensor.set_auto_whitebal(False) # 白平衡关闭#LCD初始化lcd.init()clock = time.clock() # Tracks FPS.K=5000#the value should be measured K=length*Lm# 实际的大小=K2*直径的像素K2=10.5/101#QQVGA模式下K2=10.5/139#QVGA模式下K2=10.5/279while(True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image. lcd.display(img)#lcd屏幕显示 blobs = img.find_blobs([yellow_threshold])#调用颜色阈值 if len(blobs) == 1:#如果视野中只识别到一个目标色块 # Draw a rect around the blob. b = blobs[0]#blose[0]就是识别到的色块 img.draw_rectangle((300, 0, 50,20), color=(255,0,0))#画框(x:0-320,:0-240,横着的,竖着的) img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy Lm = (b[2]+b[3])/2 #b[2]长 ,b[3]宽 length = K/Lm print(length)#长度27 print(Lm)#像素点 size=K2*Lm print(size)
转载地址:http://wxtzi.baihongyu.com/