mirror of
https://github.com/opencv/opencv.git
synced 2026-12-06 06:55:35 -06:00
isScalarLikeMat(sc, cn) previously returned true whenever rows == 1 and cols == 1 (as long as nval <= 4), without checking whether nval matches 1 or the other operand's channel count cn. As a result, a 1x1 multi-channel Mat (e.g. 1x1 CV_32FC3, nval == 3) was mistakenly treated as a scalar for a different channel count (e.g. cn == 1 when multiplied by a cv::Scalar converted to a 4x1 CV_64FC1 Mat in Mat::mul). In arithm_op, this caused s1 and s2 to both be true, demoting the actual scalar operand s2 to false and broadcasting the operands into a 4x1 CV_32FC3 result instead of a 1x1 CV_32FC3 result. Require nval == 1 || nval == cn in isScalarLikeMat so that a 1x1 Mat is only treated as scalar-like when its total element count is compatible with the target channel count.