logo

光流例程无法实现,最新版的固件不支持吗?

2018-11-13 16:13
1
小陈
# MAVLink OpticalFlow Script.
#
# This script sends out OpticalFlow detections using the MAVLink protocol to
# an LIGHT/PixHawk UAV controller for position control using your OpenMV Cam.
#
# P4 = TXD 115200,8,N,1


import sensor, image, time, pyb, struct, math

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

old = sensor.snapshot()

uart = pyb.UART(3, 115200, timeout_char = 1000)

def send_optical_flow_packet(x, y, c):
    temp = struct.pack("<bbiii",
                       0xAA,
                       0xAE,
                       int(x * 100000 ), # up sample by 4
                       int(y * 100000 ), # up sample by 4
                       int(c * 100000))
    uart.write(temp)


while(True):
    clock.tick() # 获取时间
    img = sensor.snapshot() # 获取一帧图像
    '''
    find_displacement 这个功能函数使用是是2D FFT算法获得新旧两张图像的相位移动,由于OPenMV上单片机内存的问题,只能计算
    64x64或者64*32的图片(openmv2),如果使用OPenMV3可以计算128*32或者32*128的图片
    '''
    [delta_x, delta_y, response] = old.find_displacement(img) #获取前面一张图像与刚捕获的图像之间的偏移
    old = img.copy()
    #print("%0.6fX   %0.6fY   %0.2fC   %0.2fFPS" % (delta_x, delta_y, response, clock.fps()))
    if (not (math.isnan(delta_x) or math.isnan(delta_y) or math.isnan(response))):
        send_optical_flow_packet(delta_x, delta_y, response)
b6676f19-815a-4232-af6a-7aa924692779.png
2018-11-13 16:18
I
网红小智智 星瞳科技

你程序不对。

http://book.openmv.cc/example/18-MAVLink/mavlink-opticalflow.html

1
小陈

IDE的固件版本是3.0.0

I
网红小智智 星瞳科技

你的程序不对。复制我链接里的代码。

2018-11-13 16:26
1
小陈

@kidswong999 找到原因了:因为我写的是B64x64,应该是B64X64