logo

请问有具体引用示例吗?

2023-10-24 10:32
Z
_2a5s

回复: [openMV可以实时输出时间吗?例如每一秒记录一下物体的位移然后输出时间和结果?](/topic/10555/openmv可以实时输出时间吗-例如每一秒记录一下物体的位移然后输出时间和结果)

2023-10-25 18:23
I
网红小智智 星瞳科技

import sensor, image, time
import pyb, math

green_threshold   = (   0,   80,  -70,   -10,   -0,   30)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()


last_time = None
last_blob = None
while(True):
    clock.tick()
    img = sensor.snapshot()

    blobs = img.find_blobs([green_threshold])
    if blobs:
        blob = blobs[0]
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
        now_time = pyb.millis()
        if last_blob:
            diff_time = now_time-last_time
            diff_position = math.sqrt((blob.cx()-last_blob.cx())**2 + (blob.cy()-last_blob.cy())**2)
            print(diff_position, diff_time)
        last_time = now_time
        last_blob = blob