Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: inconsistency of addition for multi-channel Mat and Scalar #16739

Open
alalek opened this issue Mar 5, 2020 · 4 comments
Open

core: inconsistency of addition for multi-channel Mat and Scalar #16739

alalek opened this issue Mar 5, 2020 · 4 comments
Labels
bug category: core future This issue can't be fixed during restrictions of the compatibility requirements pr: Discussion Required RFC

Comments

@alalek
Copy link
Member

alalek commented Mar 5, 2020

OpenCV 3.4.9 / 4.2.0:

arg1 - uint8 matrix with 3 channels:

  • Mat m__1_2_3(Size(2, 2), CV_8UC3, Scalar(1, 2, 3));

arg2:

  • 5
  • Scalar(5) (identical to Scalar(5, 0, 0, 0))
  • Scalar(5, 1e-6, 0)
  • Scalar::all(5) (identical to Scalar(5, 5, 5, 5))

Result variants:

  1. [6, 2, 3] - modified 1st channel only
  2. [6, 7, 8] - all channels are modified
# C++ code arg1
5
arg2
Scalar(5)
arg3
Scalar
(5, 1e-6, 0)
arg4
Scalar::all(5)
1 cv::add(arg1, arg2, res) 2 1 1 2
2 MatExpr
res = arg1 + arg2
1
#14738
1 1 2
3 MatExpr
res = 1.001 * arg1 + arg2
2
#14738
2
#16538
1 2

Analyse:

  • results with Scalar(5, 1e-6, 0)(arg3) and Scalar::all(5)(arg4) are consistent and adequate
  • some other cases should be be deprecated / changed / removed?
  • case with numeric scalar (5) may have designed to use with complex numbers (emulation through matrices with 2 channels) where 5 is interpreted as a real number.
  • current implicit conversion of 5 into Scalar (no explicit bug/feature) converts this into Scalar(5, 0, 0, 0). Extra overloads may help to avoid implicit conversions (but may break user code).

Related unclear stuff:

@saskatchewancatch
Copy link
Contributor

Looking at the Jiras, it seems many people expect OpenCV matrix's to behave just like in Matlab.
Perhaps behaviour should strive to be as close as possible to the way Matlab treats Matrix's?

@zchrissirhcz

This comment has been minimized.

@alalek

This comment has been minimized.

@zchrissirhcz

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: core future This issue can't be fixed during restrictions of the compatibility requirements pr: Discussion Required RFC
Projects
None yet
Development

No branches or pull requests

3 participants