简体   繁体   English

使用光流进行特征跟踪

[英]Feature tracking using optical flow

I found a similar question in the forum. 我在论坛中发现了类似的问题 But the answer in there does not answer my question. 但那里的答案并没有回答我的问题。

  • If I do feature detection (goodFeaturesToTrack) only once on the first image , and then use optical flow (calcOpticalFlowPyrLK) to track these features, the problem is: only the features detected on the first image can be tracked. 如果我在第一张图像上只进行一次特征检测(goodFeaturesToTrack),然后使用光流(calcOpticalFlowPyrLK)来跟踪这些特征,则问题是:只能跟踪第一张图像上检测到的特征。 When these features go beyond of the image, there would be no features to track. 当这些功能超出图像时,就没有可追踪的功能。

  • If I do feature detection for every new image , the feature tracking is not stable, because the feature detected last time may not be detected this time. 如果我对每个新图像进行特征检测,则特征跟踪不稳定,因为此时可能无法检测到上次检测到的特征。

I am using optical flow for 3D reconstruction. 我正在使用光流进行3D重建。 So I'm not interested in tracking what features, instead, I only care whether features in the field of view can be tracked stably. 所以我对跟踪哪些功能不感兴趣,相反,我只关心是否可以稳定地跟踪视野中的功能。 To summarize, my question is : how can I use optical flow to track old features, and in the meantime add new image features that come into the field of view and remove old features that go beyond the field of view? 总而言之, 我的问题是 :如何使用光流跟踪旧功能,同时添加进入视野的新图像功能并删除超出视野范围的旧功能?

Several approaches are possible. 有几种方法是可行的。 A good method goes like this: 一个好的方法是这样的:

  1. in Frame 1 detect N features, this is the Keyframe m=1 在第1帧中检测N个特征,这是关键帧 m = 1
  2. in Frame k track the features by optical flow 在帧k中通过光流跟踪特征
  3. in Frame k if the number of successfully tracked features drops under N/2: 在帧k中,如果成功跟踪的功能的数量在N / 2下降:
    • this frame is the keyframe m+1 这个帧是关键帧 m + 1
    • compute the homography or the fundamental matrix describing the motion between the keyframes m and m+1 计算描述关键帧 m和m + 1之间运动的单应性或基本矩阵
    • detect N features and discard the old ones 检测N个特征并丢弃旧特征
    • k := k+1 go to 2 k:= k + 1转到2

In this method basically you estimate the camera motion between the last two keyframes. 在这种方法中,您基本上可以估计最后两个关键帧之间的相机运动。

Since you didn't mention what approach is used for 3D reconstruction I assumed either H or F are computed to estimated motion first. 由于您未提及用于3D重建的方法,因此我假设HF首先计算为估计运动。 To estimate them accurately the baseline between the keyframes should be as wide as possible. 为了准确估计它们,关键帧之间的基线应尽可能宽。 In general, the best strategy is take into account the rough motion model of the camera. 通常,最佳策略是考虑相机的粗略运动模型。 If the camera is held by hand a different strategy should be used compared to when the camera is fixed on the top of a car or a robot. 如果手持相机,则应将相机固定在汽车或机器人顶部时使用不同的策略。 I can provide a minimal working example in Python if that helps, let me know. 如果有帮助,我可以在Python中提供一个最小的工作示例,请告诉我。

Just for documentation purposes, there are several good GPU / C++ implementations of optical flow tracking. 仅出于文档目的,有一些良好的GPU / C ++光流跟踪实现。 Your code may be better for your purposes, but if all you need is the output data of the tracks, consider checking any of the following sources: here , here , or here . 您的代码可能更适合您的目的,但如果您只需要轨道的输出数据,请考虑检查以下任何来源: 此处此处此处

There is another good way to add new features to the existing ones. 还有另一种向现有功能添加新功能的好方法。 You can pass a mask into cv::goodFeaturesToTrack() . 您可以将掩码传递给cv::goodFeaturesToTrack() So you would create a new Mat (same size as original image, type: CV_8UC1 ), set all pixels to 255 and draw each feature point as a black circle into this Mat. 因此,您将创建一个新Mat(与原始图像大小相同, type: CV_8UC1 ),将所有像素设置为255并将每个特征点绘制为此Mat中的黑色圆圈。 When you pass this mask into goodFeaturesToTrack() those black circles will be skipped by the function. 当您将此蒙版传递给goodFeaturesToTrack() ,该函数将跳过这些黑色圆圈。

I would also recommend limiting the amount of features. 我还建议限制功能的数量。 Let's say you limit it to MAX_FEATURES = 300 . 假设您将其限制为MAX_FEATURES = 300 You then check every cycle whether you have less tracks than MAX_FEATURES - z (eg z = 30) . 然后检查每个周期是否有比MAX_FEATURES - z (eg z = 30)更少的轨迹MAX_FEATURES - z (eg z = 30) In case you do, search for up to z new features as stated above and add them to your feature-container. 如果您这样做,请按上述方法搜索最多z个新功能,并将它们添加到您的功能容器中。

Also note that you have to actively delete Features when tracking failed. 另请注意,在跟踪失败时您必须主动删除功能。 You will therefore have to look at the status output of calcOpticalFlowPyrLK . 因此,您必须查看calcOpticalFlowPyrLK的状态输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM