Operating System / Platform => Linux Ubuntu 16.04 - 64 bit
Compiler => GCC 5.4.0
Detailed description
When calling cv::aruco::CharucoBoard::draw() using specific board and image sizes, code crashes with OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create.
Specifically, I've been able to reproduce the problem when creating a 7x5 board and then drawing it at size 1600x1200 pixels.
This code triggers the bug.
Changing the size of the board to, e.g. 9x7, or changing the size of the image to, eg. 1600x1201, does not trigger the bug.
if((outCorners[0].y == outCorners[1].y) && (outCorners[1].x == outCorners[2].x)) {
// marker is aligned to image axes
marker.copyTo(out(Rect(outCorners[0], dst_sz)));
continue;
}
When using the parameters above, dst_sz == Size(172, 171) whereas marker.size() == Size(172,172), which causes the crash.
I managed to fix it simply by adding the condition that marker.size() == dst_sz. It seems to work correctly, but I'm not expert enough on the matter to know whether it's the right fix.
The problem is caused by the rounding in line 1678. I think your fix is correct, but it can block the optimization in some cases. Take a look at the my fix: #1230
System information (version)
Detailed description
When calling
cv::aruco::CharucoBoard::draw()
using specific board and image sizes, code crashes withOpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create
. Specifically, I've been able to reproduce the problem when creating a 7x5 board and then drawing it at size 1600x1200 pixels.Steps to reproduce
This code triggers the bug. Changing the size of the board to, e.g. 9x7, or changing the size of the image to, eg. 1600x1201, does not trigger the bug.
Possible fix
I've managed to trace the bug to
cv::aruco::_drawPlanarBoardImpl()
at line 1683 (https://github.com/opencv/opencv_contrib/blob/master/modules/aruco/src/aruco.cpp#L1683):When using the parameters above,
dst_sz == Size(172, 171)
whereasmarker.size() == Size(172,172)
, which causes the crash. I managed to fix it simply by adding the condition thatmarker.size() == dst_sz
. It seems to work correctly, but I'm not expert enough on the matter to know whether it's the right fix.