主要内容

本页采用了机器翻译。点击此处可查看英文原文。

opticalFlowLK

用于基于 Lucas-Kanade 方法估计光流的对象

说明

使用卢卡斯-卡纳德 (Lucas-Kanade) 算法创建一个光流对象,用于估计移动对象的方向和速度。使用对象函数 estimateFlow 来估计光流向量。使用 reset 对象函数,可以重置光流对象的内部状态。

创建对象

描述

opticFlow = opticalFlowLK 返回一个光流对象,您可以利用它来估计视频中移动物体的方向和速度。光流是采用卢卡斯-卡纳德 (Lucas-Kanade) 算法进行估计的。

opticFlow = opticalFlowLK('NoiseThreshold',threshold) 返回一个光流对象,其中属性 'NoiseThreshold' 被指定为一个 Name,Value 对。请将属性名称用引号括起来。

例如,opticalFlowLK('NoiseThreshold',0.05)

示例

属性

全部展开

降噪阈值,指定为一个正标量。随着该数值增大,物体的运动对光流计算的影响会减小。

对象函数

estimateFlow估计光流
resetReset the internal state of the optical flow estimation object

示例

全部折叠

读取一个视频文件。指定要读取的帧的时间戳。

vidReader = VideoReader('visiontraffic.avi','CurrentTime',11);

创建一个用于估计光流的光流对象,采用卢卡斯-卡纳德 (Lucas-Kanade) 方法。指定降噪的阈值。输出是一个光流对象,用于指定光流估计方法及其属性。

opticFlow = opticalFlowLK('NoiseThreshold',0.009);

创建一个自定义图窗,用于可视化光流向量。

h = figure;
movegui(h);
hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow Vectors');
hPlot = axes(hViewPanel);

读取图像帧并将其转换为灰度图像。根据连续的图像帧估计光流。显示当前图像帧,并将光流向量以箭头图的形式绘制出来。

while hasFrame(vidReader)
    frameRGB = readFrame(vidReader);
    frameGray = im2gray(frameRGB);
    flow = estimateFlow(opticFlow,frameGray);
    imshow(frameRGB)
    hold on
    plot(flow,'DecimationFactor',[5 5],'ScaleFactor',10,'Parent',hPlot);
    hold off
    pause(10^-3)
end

Figure contains an axes object and an object of type uipanel. The hidden axes object contains 2 objects of type image, quiver.

Figure contains an axes object and an object of type uipanel. The hidden axes object contains 2 objects of type image, quiver.

算法

全部展开

要计算两帧图像之间的光流,必须求解以下光流约束方程:

Ixu+Iyv+It=0

  • IxIyIt 是图像亮度的时空导数。

  • u 表示水平光流。

  • v 表示垂直光流。

参考

[1] Barron, J. L., D. J. Fleet, S. S. Beauchemin, and T. A. Burkitt. “ Performance of optical flow techniques.” In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR),236-242. Champaign, IL: CVPR, 1992.

扩展功能

全部展开

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

GPU 代码生成
使用 GPU Coder™ 为 NVIDIA® GPU 生成 CUDA® 代码。

版本历史记录

在 R2015a 中推出