fix type cast in drawDetectedMarkers, drawDetectedCornersCharuco, drawDetectedDiamonds#24247
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); |
There was a problem hiding this comment.
I propose alternative:
CV_Assert(_charucoCorners.channels() == 2);
...
_charucoCorners.getMat().convertTo(..., ...);
There was a problem hiding this comment.
No need to limit type here. Just use proper conversions.
There was a problem hiding this comment.
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.
InputArray has total() method. getMat() is redundant.
There was a problem hiding this comment.
removed getMat()
d65f3d3 to
093878a
Compare
4dde75d to
b7b8183
Compare
4bfb003 to
587dc3f
Compare
| 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.
It makes sense, to check if the input is already 32SC2. convertTo does not check it.
There was a problem hiding this comment.
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.
The same for type check.
There was a problem hiding this comment.
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.
The same test type Point2d and Point2d. Should it be 2i in the second case?
There was a problem hiding this comment.
fixed:
vector<vector<Point2i>> detected_int = {{Point(0, 0), Point(10, 0), Point(10, 10), Point(0, 10)}};
587dc3f to
fdec321
Compare
fdec321 to
8f24080
Compare
| 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.
drawDetectedCornersCharuco is called for _float, but checked for _int. Also _double version is initialized, but not used.
There was a problem hiding this comment.
detected_int and detected_float are equal, using int will help to avoid rounding errors
the "_double" version will be added
8f24080 to
100b163
Compare
100b163 to
ae1d1b6
Compare
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 at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.