Assertion in cv::OutputArray::create fails if used on submatrix that is the correct size and type. (Bug #1997)
Description
The cv::OutputArray::create
function will crash if it is called on a submatrix that is already the correct size and type.
Here is an example (Windows 7 x64 Visual Studio 2010):
1cv::Mat mat(cv::Size(512, 512), CV_8U);
2cv::Size submatSize = cv::Size(256, 256);
3cv::OutputArray outputArray = mat(cv::Rect(cv::Point(), submatSize));
4array<int, 2> sizeArray = {submatSize.width, submatSize.height};
5// This will cause an assertion to fail, even though the submatrix is the correct size and type.
6outputArray.create(sizeArray.size(), sizeArray.data(), mat.type());
Related issues
duplicates Bug #1918: Mat.copyTo with mask broken | Cancelled | 2012-05-10 |
Associated revisions
Added test for #1997; fixed build warnings
Merge pull request #1997 from alalek:tapi_fix_memleaks
History
Updated by Andrey Kamaev almost 13 years ago
I've added a test for your case but it runs without an assertion.
- Status changed from Open to Cancelled
- Target version set to 2.4.1
- Description changed from The cv::OutputArray::create function will crash if it is called on a submatri... to The @cv::OutputArray::create@ function will crash if it is called on a submat... More
- Assignee changed from Vadim Pisarevsky to Andrey Kamaev
Updated by Daniel Shields almost 13 years ago
The trunk branch has the problem fixed.
The offending portion started at line 1350 of matrix.cpp:
1 if(fixedType())
2 {
3 if(CV_MAT_CN(type) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
4 type = m.type();
5 else
6 CV_Assert(!fixedType() || (CV_MAT_CN(type) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0));
7 }
The assert in the above code will always fire.
The most recent version of this code is:
1 if(fixedType())
2 {
3 if(CV_MAT_CN(type) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
4 type = m.type();
5 else
6 CV_Assert(CV_MAT_TYPE(type) == m.type());
7 }
This version appears correct.
Updated by Andrey Kamaev almost 13 years ago
Well, marked as duplicate.