logo

颜色识别测距怎么在方框的旁边显示距离。不是通过串口打印。是直接显示在方框的旁边

2019-11-09 14:47
G
滚滚滚
# Measure the distance

#



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   = (12, 100, 30, 127, -39, 50)

# 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=1310#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)
        print(b[5], b[6])
2019-11-10 14:28
I
网红小智智 星瞳科技

https://book.openmv.cc/image/drawing.html#%E5%86%99%E5%AD%97

使用 draw_string函数

2019-11-10 16:24
G
滚滚滚

不是输出固定字符,而是想把openmv测到的实时距离显示在边框上。怎么引用距离

2019-11-11 12:54
I
网红小智智 星瞳科技

把变量转成字符串使用str函数