You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So in several of the operator / () overloads, in the right places, CV_ERROR will have to be thrown if one of the operands to the expression is invalid.
@berak and @alalek , I think more operator overloads may be suffering from the same issue. Here is an example of the boolean compare operator not doing an expected operation.
int main()
{
Mat a = Mat::ones(2, 2, CV_8U);
Mat b;
cout << (a == b) << endl;
return 0;
}
Produces (in 3.4 dev on Ubuntu)
[255, 255;
255, 255]
which doesn't make sense, unless I've totally overlooked something. Element-wise boolean with "nothing" should not return true values.
A list of more operations that are affected, in addition to the ones above:
Mat ones = Mat::ones(2, 2, CV_8U);
Mat zeros = Mat::zeros(2, 2, CV_8U);
Mat empty;
Mat result;
int s = 9;
int alpha = 10;
...
// In each case below, result seems to get an empty matrix
result = ones > empty;
result = min(empty, s);
result = min(s, empty);
result = s + empty;
result = empty + s;
result = s - empty;
result = empty - s;
result = empty * alpha;
result = alpha * empty;
result = -empty;
result = abs(empty);
result = empty.t();
In other cases where an exception is actually thrown somewhere, it is not graceful and consistent behaviour between the various MatExpr schemes.
@alalek As an example, here is what I propose.... in MatExpr min for example, to error out gracefully.
MatExpr min(const Mat& a, const Mat& b)
{
CV_INSTRUMENT_REGION();
//Check for emptiness of operands and throw exception if a Mat input is empty.
if (a.empty() || b.empty())
{
CV_Error(Error::StsBadArg, "One or more matrix operands are empty\n");
}
MatExpr e;
MatOp_Bin::makeExpr(e, 'm', a, b);
return e;
}
Similarly for other expression handlings. The emptiness checks can be done as a separate function.
I haven't tried this out but I suspect this should work.
Activity
alalek commentedon Oct 22, 2019
I believe we need check much early than mentioned code (
MatOp_Bin::assign()) - somewhere inoperator / ()saskatchewancatch commentedon Oct 24, 2019
So in several of the operator / () overloads, in the right places, CV_ERROR will have to be thrown if one of the operands to the expression is invalid.
berak commentedon Oct 24, 2019
btw, similar problem for
| & ^operators heresaskatchewancatch commentedon Oct 25, 2019
@berak and @alalek , I think more operator overloads may be suffering from the same issue. Here is an example of the boolean compare operator not doing an expected operation.
Produces (in 3.4 dev on Ubuntu)
which doesn't make sense, unless I've totally overlooked something. Element-wise boolean with "nothing" should not return true values.
saskatchewancatch commentedon Nov 20, 2019
A list of more operations that are affected, in addition to the ones above:
In other cases where an exception is actually thrown somewhere, it is not graceful and consistent behaviour between the various MatExpr schemes.
saskatchewancatch commentedon Nov 20, 2019
@alalek As an example, here is what I propose.... in
MatExpr minfor example, to error out gracefully.Similarly for other expression handlings. The emptiness checks can be done as a separate function.
I haven't tried this out but I suspect this should work.
I can have a PR for this.
alalek commentedon Nov 20, 2019
Looks good to me.
Please remove trailing "\n" from the error description.
Also add simple test (in test_operations.cpp) with these checks:
saskatchewancatch commentedon Nov 21, 2019
#15966 created to start work on this. More checks and tests coming.