Skip to content
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

Fix sampling for version multiplying factor #22025

Merged

Conversation

AleksandrPanov
Copy link
Contributor

@AleksandrPanov AleksandrPanov commented May 23, 2022

Merge with extra: opencv/opencv_extra#976

fixes #21287

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@AleksandrPanov AleksandrPanov force-pushed the fix_samplingForVersion_multiplyingFactor branch from 855f948 to 09e0eb7 Compare May 27, 2022 13:44
Comment on lines 2479 to 2481
for (int i = 0, r = 0; i < version_size; i++ && r < postIntermediate.rows, r+= delta_rows)
{
for (int c = 0; c < postIntermediate.cols; c += delta_cols)
for (int j = 0, c = 0; j < version_size; j++ && c < postIntermediate.cols, c+= delta_cols)
Copy link
Member

Choose a reason for hiding this comment

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

Overcomplicated (need to rewrite) or just invalid "for" loops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@AleksandrPanov AleksandrPanov force-pushed the fix_samplingForVersion_multiplyingFactor branch 3 times, most recently from 80e437f to 15b05c3 Compare June 1, 2022 23:47
@AleksandrPanov AleksandrPanov force-pushed the fix_samplingForVersion_multiplyingFactor branch from 15b05c3 to 9b02b93 Compare June 2, 2022 02:11
@@ -106,10 +106,11 @@ PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, decodeMulti)
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
::testing::Values(
"version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
"version_5_down.jpg", "version_5_left.jpg", "version_5_right.jpg", "version_5_up.jpg", "version_5_top.jpg",
Copy link
Member

Choose a reason for hiding this comment

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

We could use C++ comments here: /* "version_5_right.jpg", */ instead of whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -2369,7 +2369,8 @@ bool QRDecode::samplingForVersion()
CV_TRACE_FUNCTION();
const double multiplyingFactor = (version < 3) ? 1 :
(version == 3) ? 1.5 :
version * (version + 1);
(version < 6) ? version*(version+1) :
version;
Copy link
Member

Choose a reason for hiding this comment

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

version;

version * 5 ?

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Jun 3, 2022

Choose a reason for hiding this comment

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

fixing the tail processing process allows to reduce multiplyingFactor to 1 and skip strange resize() step

I want to add a few more tests and skip resize() step or reduce the multiplyingFactor to 2, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now multiplyingFactor:

    const double multiplyingFactor = (version < 3)  ? 1. :
                                     (version == 3) ? 2. :
                                     3.;

Comment on lines 2389 to 2390
deltas_rows[(i*version_size)/abs(skipped_rows)+(version_size/abs(skipped_cols)-1)/2]
+= skipped_rows > 0 ? 1 : -1;
Copy link
Member

Choose a reason for hiding this comment

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

Please separate index calculation to simplify code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    for (int i = 0; i < abs(skipped_rows); i++) {
        // fix deltas_rows at each skip_step
        const double skip_step = static_cast<double>(version_size)/abs(skipped_rows);
        const int corrected_index = static_cast<int>(i*skip_step + skip_step/2);
        deltas_rows[corrected_index] += skipped_rows > 0 ? 1 : -1;
    }

+= skipped_cols > 0 ? 1 : -1;
}

const double totalFrequencyElem = countNonZero(postIntermediate) / static_cast<double>(postIntermediate.total());
Copy link
Member

Choose a reason for hiding this comment

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

Looks like postIntermediate is not a binary (0/255) image. So there is no sense to use countNonZero() here.

Perhaps we want to use norm(postIntermediate, NORM_L1 | NORM_RELATIVE); here.


Do we have 0.5 value here?

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Jun 3, 2022

Choose a reason for hiding this comment

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

actually postIntermediate is binary (0/255) image in this case:

  1. no_border_intermediate is binary
  2. postIntermediate = resize(no_border_intermediate, newFactorSize, INTER_AREA)
  3. newFactorSize is integer and InterpolationFlags is INTER_AREA, so postIntermediate is binary (0/255) image

I checked this in tests. Also totalFrequencyElem must be around 0.5, otherwise most of the tests will fail.

@AleksandrPanov AleksandrPanov force-pushed the fix_samplingForVersion_multiplyingFactor branch from 27e28c2 to 98a95d6 Compare June 3, 2022 16:13
@AleksandrPanov AleksandrPanov marked this pull request as ready for review June 3, 2022 16:44
@AleksandrPanov
Copy link
Contributor Author

@alalek, fixed the issues

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.

2 participants