-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add robust local optical flow (RLOF) implementations #1940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add robust local optical flow (RLOF) implementations #1940
Conversation
…oved pyramidal iterative Lucas-Kanade approach. This implementations contains interfaces for sparse optical flow for feature tracking and dense optical flow based on sparse-to-dense interpolation schemes. Add performance and accuracy tests have been implementation as well as documentation with the related publications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
Below are comments from high level review.
Public interfaces look good.
More detailed review will be later (please make builds green).
|
||
License Agreement | ||
For Open Source Computer Vision Library | ||
(3-clause BSD License) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using of short form of license header:
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
or avoid using of tabs
modules/optflow/doc/optflow.bib
Outdated
title = {Robust Local Optical Flow: Dense Motion Vector Field Interpolation}, | ||
booktitle = {Picture Coding Symposium}, | ||
year = {2016}, | ||
pages = {1--5}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix indentation (replace tabs)
namespace optflow | ||
{ | ||
//! @addtogroup optflow | ||
//! @{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid extra indentation in "namespaces" - it is not necessary.
@@ -0,0 +1,309 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this file? Looks like it is a copy of existed one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were right. The file has been removed:
- fix optflow.bib indentation - remove optflow_o.hpp - change RLOFOpticalFlowParameter interfaces to Ptr<RLOFOpticalFlowParameter> to remove error on building. Fix warnings
fix perf and accuracy tests
…r to enable python wrapper interfaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed massive but minor updates (spaces, includes, static, etc). Please take a look.
|
||
// Initialize point grid | ||
int stepr = prevPyramids[0]->m_Image.rows / 30; | ||
int stepc = prevPyramids[0]->m_Image.rows / 40; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_Image.cols
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks that was a bug
for( y = 0; y < winSize.height; y++ ) | ||
{ | ||
const uchar* src = (const uchar*)I.data + (y + iprevPt.y)*step + iprevPt.x*cn; | ||
const short* dsrc = (const short*)derivI.data + (y + iprevPt.y)*dstep + iprevPt.x*cn2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid using "data" and "step" calculations. Use .ptr<mat_type>(row, col) instead. Remove using of "steps" in other places too.
const uchar* src = I.ptr<uchar>(y + iprevPt.y, iprevPt.x);
const short* dsrc = derivI.ptr<short>(y + iprevPt.y, iprevPt.x);
_mm_loadl_epi64((const __m128i*)(Jptr + x)), z); | ||
__m128i v01 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + cn)), z); | ||
__m128i v10 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + step)), z); | ||
__m128i v11 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + step + cn)), z); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jptr + step
=> Jptr1
where:
const uchar* Jptr = J.ptr<uchar>(y + inextPt.y, inextPt.x);
CV_DbgCheckLT(y + inextPt.y + 1, J.rows, ""); // or use std::min(J.rows - 1, y + inextPt.y + 1) below
const uchar* Jptr1 = J.ptr<uchar>(y + inextPt.y + 1, inextPt.x);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of step has been removed with the current pull
return ret; | ||
/* | ||
for (int y = 0; y < in.rows; y++) { | ||
for (int x = 0; x < in.cols; x++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this commented code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet will be removed
I'm sorry. I though that patch is almost complete.
Please don't do this again.
|
This is why we asking to use
Code tries to access pixels out of the buffer:
Perhaps "out of range" (lost) points should be filtered out. |
Rebased commits without "merges" are here: https://github.com/alalek/opencv_contrib/commits/pr1940 |
I am sorry for the circumstances. To not cause any new conflicts who should I proceed to integrate the bugfixes? |
It would be nice if you can grab changes from https://github.com/alalek/opencv_contrib/commits/pr1940 |
int step = static_cast<int>(img.step1()); | ||
const cv::Point3_<uchar> * tval = img.ptr<cv::Point3_<uchar>>(); | ||
tval += c; | ||
tval += r * step / 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more manual pointer arithmetic:
-int step = static_cast<int>(img.step1());
-const cv::Point3_<uchar> * tval = img.ptr<cv::Point3_<uchar>>();
-tval += c;
-tval += r * step / 3;
+CV_DbgAssert(img.type() == CV_8UC3);
+const cv::Point3_<uchar> * tval = img.ptr< cv::Point3_<uchar> >(r, c);
"if" check above should be updated too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this function because it is not used anymore. Instead computation is done by the HorizontalCrossSegmentation class
@tsenst Do you plan adding more commits into this PR? |
I have done some tests on Optical Flow datasets to compare the accuracy of this implementation with the origin one. The results were satisfying. So from my side I am not planning any new commits. |
prevImage, currImage and derivI as well as changing the offset of the points in the invoker classes. add some static_cast to avoid warning remove 50 grid size sample from perf test. This grid size is to sparse for the epic interpolation remove notSameColor function since it is not used anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thank you 👍
The RLOF method is an improved pyramidal iterative Lucas-Kanade approach. This implementations contains interfaces for sparse optical flow for feature tracking and dense optical flow based on sparse-to-dense interpolation schemes.
Add performance and accuracy tests have been implementation as well as documentation with the related publications