logo

在小球测距的时候,视野多出一个小球,如何保持测的是第一个小球

2019-07-18 22:09
6
dn42

import sensor, image, time

# For color tracking to work really well you should ideally be in a very, very,

# very, controlled enviroment where the lighting is constant...

yellow_threshold = ( 56, 83, 5, 57, 63, 80)

# You may need to tweak the above settings for tracking green things...

# Select an area in the Framebuffer to copy the color settings.

sensor.reset() # Initialize the camera sensor.

sensor.set_pixformat(sensor.RGB565) # use RGB565.

sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.

sensor.skip_frames(10) # Let new settings take affect.

sensor.set_auto_whitebal(False) # turn this off.

clock = time.clock() # Tracks FPS.

K=5000#the value should be measured

while(True):

clock.tick() # Track elapsed milliseconds between snapshots().

img = sensor.snapshot() # Take a picture and return the image.

blobs = img.find_blobs([yellow_threshold])

if len(blobs) == 1:

# Draw a rect around the blob.

b = blobs[0]

img.draw_rectangle(b[0:4]) # rect

img.draw_cross(b[5], b[6]) # cx, cy

Lm = (b[2]+b[3])/2

length = K/Lm

print(length)

2019-07-19 15:31
I
网红小智智 星瞳科技

https://singtown.com/learn/49239/

程序里是追最大的色块,也就是最近的小球。