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 CORNER REFINE CONTOUR #3186

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

AleksandrPanov
Copy link
Contributor

@AleksandrPanov AleksandrPanov commented Feb 28, 2022

fix cv::aruco::detectMarkers consumes all available memory when CORNER_REFINE_CONTOUR #2738

The problem is that undistortPoints() is missing for nCorners. Therefore, the algorithm does not find any corner points:

	for ( unsigned int i =0; i < nContours.size(); i++ ) {
		for(unsigned int j=0; j<4; j++){
			if ( nCorners[j] == contour2f[i] ){ // nCorners[j] != contour2f[I] after `undistortPoints()`
				cornerIndex[j] = i;
				group=j;
			}
		}
		cntPts[group].push_back(contour2f[i]);
	}

The most logical solution is to make undistort() for the original image and look for ArUco markers on an undistorted image.

Also added a check that each of the four corners is found to avoid an infinite loop.

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_CORNER_REFINE_CONTOUR branch from 2e003af to 6004438 Compare February 28, 2022 17:23
Comment on lines +952 to +938
for (int i = 0; i < 4; i++)
CV_Assert(cornerIndex[i] != -1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check that each of the four corners is found.

// saves extra group into corresponding
if( !cntPts[4].empty() ){
CV_CheckLT(group, 4, "FIXIT: avoiding infinite loop: implementation should be revised: https://github.com/opencv/opencv_contrib/issues/2738");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If each (or at least one) of the 4 corners is found, then group will not be equal to 4.

@AleksandrPanov AleksandrPanov force-pushed the fix_CORNER_REFINE_CONTOUR branch from 6004438 to 77e648f Compare March 1, 2022 07:59
@AleksandrPanov AleksandrPanov marked this pull request as ready for review March 1, 2022 08:59
* @param cameraMatrix optional input 3x3 floating-point camera matrix
* \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
* @param distCoeff optional vector of distortion coefficients
* \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to add reference to undistortPoints and fisheye::undistortPoints to @sa. And also add note like "The function does not correct lens distortion or takes it into account. It's recommended to undistort input image with corresponging camera model, if camera parameters are known."

@AleksandrPanov AleksandrPanov force-pushed the fix_CORNER_REFINE_CONTOUR branch 2 times, most recently from 484e030 to 7fa02c4 Compare March 4, 2022 19:20
@AleksandrPanov AleksandrPanov force-pushed the fix_CORNER_REFINE_CONTOUR branch from 7fa02c4 to ef980e7 Compare March 4, 2022 21:57
@opencv-pushbot opencv-pushbot merged commit 631cefc into opencv:3.4 Mar 16, 2022
@alalek alalek mentioned this pull request Mar 26, 2022
@opencv-pushbot opencv-pushbot mentioned this pull request Apr 23, 2022
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.

cv::aruco::detectMarkers consumes all available memory when CORNER_REFINE_CONTOUR
4 participants