Skip to content

FREAK : better rounding off for weighted dx and dy of orientation pairs #2440

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

Merged
merged 3 commits into from
Mar 7, 2020

Conversation

rindranil
Copy link
Contributor

@rindranil rindranil commented Feb 26, 2020

Merge with extra: opencv/opencv_extra#721

resolves #2430, when value of dx/(norm_sq) is -ve, adding -0.5 will lead to better rounding off.

@alalek
Copy link
Member

alalek commented Feb 26, 2020

Thank you for contribution!

As a "bugfix" this patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

So, please:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

@rindranil rindranil changed the base branch from master to 3.4 February 26, 2020 20:23
orientationPairs[m].weight_dx = int((dx/(norm_sq))*4096.0+0.5);
orientationPairs[m].weight_dy = int((dy/(norm_sq))*4096.0+0.5);
orientationPairs[m].weight_dx = int((dx/(norm_sq))*4096.0+0.5*((dx>0)-(dx<0)));
orientationPairs[m].weight_dy = int((dy/(norm_sq))*4096.0+0.5*((dy>0)-(dy<0)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use cvRound() instead of 0.5 hack and "int" cast.

Another question is it allowed to weight_dx/dy become zero or negative?
Usually "weight" should not be negative. May be there is lost abs() call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weight_dx/dy can be negative to preserve the sense of direction
direction0 += delta*(orientationPairs[m].weight_dx)/2048;
direction1 += delta*(orientationPairs[m].weight_dy)/2048;
where delta is the difference in mean intensity between two pairs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But after using cvRound() tests are getting failed due to bad accuracy.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression test may fail on such updates - check is usually very strong.
Primary tests are quality tests, like RotationInvariance or checking keypoints.

Testdata for regression test should be updated too. Please clone opencv_extra and open PR with updated file in testdata/cv/features2d/descriptor_extractors (use the same branch name freak_rounding_bug).
Usually it is enough to remove corresponding file and run test (it would generate new data).

Comment on lines +672 to +675
const int x_left = cvRound(xf-radius);
const int y_top = cvRound(yf-radius);
const int x_right = cvRound(xf+radius+1);//integral image is 1px wider
const int y_bottom = cvRound(yf+radius+1);//integral image is 1px higher
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just cvFloor() / cvCeil()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose when xf-radius is 2.9 and 2.1, it will be more sensible to assign 3 and 2 respectively in x_left.

@rindranil
Copy link
Contributor Author

I have sent a PR(opencv/opencv_extra#721) for updating test data.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you for contribution 👍

@alalek alalek merged commit 9c0ae27 into opencv:3.4 Mar 7, 2020
@alalek alalek mentioned this pull request Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FREAK: invalid rounding of weight_d* of orientation pairs.
2 participants