-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Guard against const matrix, misleading assert #18349
Copy link
Copy link
Closed
Labels
Milestone
Description
Consider the following (wrong) code :
cv::Mat m1(cv::Size(128, 128), CV_32FC1);
cv::Mat m2(cv::Size(128, 128), CV_32FC1);
const cv::Mat m3;
cv::multiply(m1, m2, m3, 1, m1.type());
Since m3 is const, it is not allowed to be allocated by cv::multiply() and an assert will be raised.
OpenCV(4.4.0) Error: Unspecified error (> (expected: 'm.type() == CV_MAT_TYPE(mtype)'), where 'm.type()' is 0 (CV_8UC1) must be equal to 'CV_MAT_TYPE(mtype)' is 5 (CV_32FC1)
If m3 is pre-allocated, the const flag won't be a problem and it will run correctly.
Could it be possible to get a better error message when const prevents attended result ?
In the given example, the "const" flag was obvious, but it is less explicit inside a const method, for instance.
class A
{
public:
A(void):m1(cv::Size(128,128), CV_32FC1),m2(cv::Size(128,128), CV_32FC1) {}
public:
void f(void) const
{
cv::multiply(m1, m2, m3, 1, m1.type());//m3 is const here, so an error is raised as well, and it is not so easy to figure it out
}
public:
cv::Mat m1;
cv::Mat m2;
cv::Mat m3;
};
Reactions are currently unavailable