>>> 星瞳科技|OpenMV中国官方网站 <<<

>>> 星瞳科技店铺地址|OpenMV中国官方代理,全球九大代理商之一 <<<

>>> OpenMV3 Cam M7 官方高配版上市啦~戳我戳我戳我~ <<<

>>> 星瞳科技-OpenMV中文教程网 <<<

此例程为09-feature-Detection-optical_flow.py
本例程的目标是实现光流检测。

# Optical Flow Example
#
# Your OpenMV Cam can use optical flow to determine the displacement between
# two images. This allows your OpenMV Cam to track movement like how your laser
# mouse tracks movement. By tacking the difference between successive images
# you can determine instaneous displacement with your OpenMV Cam too!

import sensor, image, time

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.B64x32) # or B40x30 or B64x64
clock = time.clock() # Tracks FPS.

# NOTE: The find_displacement function works by taking the 2D FFTs of the old
# and new images and compares them using phase correlation. Your OpenMV Cam
# only has enough memory to work on two 64x64 FFTs (or 128x32, 32x128, or etc).
old = sensor.snapshot()
#先获取一张图片

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    [delta_x, delta_y, response] = old.find_displacement(img)
    #delta_x delta_y分别表示 x y 方向上,这一帧图像相比上帧图像移动的像素数目。

    old = img.copy()

    print("%0.1f X\t%0.1f Y\t%0.2f QoR\t%0.2f FPS" % \
        (delta_x, delta_y, response, clock.fps()))

在terminal中查看运行效果: