Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
fix type cast in drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds#24247
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
fix type cast in drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds#24247
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| (_image.getMat().channels() ==1 || _image.getMat().channels() ==3)); | ||
| CV_Assert((_charucoCorners.getMat().total() == _charucoIds.getMat().total()) || | ||
| _charucoIds.getMat().total() ==0); | ||
| CV_Assert(_charucoCorners.getMat().type() == CV_32FC2); |
asmorkalovSep 8, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 propose alternative:
CV_Assert(_charucoCorners.channels() == 2);..._charucoCorners.getMat().convertTo(..., ...);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.
No need to limit type here. Just use proper conversions.
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.
then I will remove the limits from all functions (drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds)
| _charucoIds.getMat().total() ==0); | ||
| CV_Assert(_charucoCorners.getMat().type() == CV_32FC2); | ||
| size_t nCorners = _charucoCorners.getMat().total(); |
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.
InputArray hastotal() method. getMat() is redundant.
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.
removed getMat()
d65f3d3 to093878aCompare4dde75d tob7b8183Compare4bfb003 to587dc3fCompare| Mat currentMarker = _corners.getMat(i); | ||
| CV_Assert(currentMarker.total() ==4 && currentMarker.type() == CV_32FC2); | ||
| CV_Assert(currentMarker.total() ==4 && currentMarker.channels() ==2); | ||
| currentMarker.convertTo(currentMarker, CV_32SC2); |
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.
It makes sense, to check if the input is already32SC2.convertTo does not check it.
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.
added check:
if (currentMarker.type() != CV_32SC2) currentMarker.convertTo(currentMarker, CV_32SC2);| Mat currentMarker = _corners.getMat(i); | ||
| CV_Assert(currentMarker.total() ==4 && currentMarker.type() == CV_32FC2); | ||
| CV_Assert(currentMarker.total() ==4 && currentMarker.channels() ==2); | ||
| currentMarker.convertTo(currentMarker, CV_32SC2); |
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 same for type check.
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.
added check:
if (currentMarker.type() != CV_32SC2) currentMarker.convertTo(currentMarker, CV_32SC2);| vector<vector<Point2d>> detected_double = {{Point2d(0.,0.),Point2d(10.,0.),Point2d(10.,10.),Point2d(0.,10.)}}; | ||
| vector<vector<Point2d>> detected_int = {{Point(0,0),Point(10,0),Point2d(10,10),Point2d(0,10)}}; |
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 same test typePoint2d andPoint2d. Should it be2i in the second case?
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.
fixed:vector<vector<Point2i>> detected_int = {{Point(0, 0), Point(10, 0), Point(10, 10), Point(0, 10)}};
587dc3f tofdec321Comparefdec321 to8f24080Compare| for (size_t i =0ull; i <4ull; i++) { | ||
| m =moments(contours[i]); | ||
| detectedCenter =Point(cvRound(m.m10/m.m00),cvRound(m.m01/m.m00)); | ||
| ASSERT_TRUE(find(detected_int[0].begin(), detected_int[0].end(), detectedCenter) != detected_int[0].end()); |
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.
drawDetectedCornersCharuco is called for _float, but checked for _int. Also _double version is initialized, but not used.
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.
detected_int and detected_float are equal, using int will help to avoid rounding errors
the "_double" version will be added
8f24080 to100b163Compare100b163 toae1d1b6Compare
asmorkalov left a comment
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.
👍
Uh oh!
There was an error while loading.Please reload this page.
Point2f(CV_32FC2) for detected corners. But this corners are casted tointlater in the code.Strict input data requirements have been removed. Added only the requirement to have 2 channels. The input corners are then casted to CV_32SC2.
added tests
Pull Request Readiness Checklist
See details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.