0

Using the class Scalar implemented in OpenCV, I didn't understand what is the difference between this code:

Mat test;
test = Scalar::all(0);

and this:

Mat test = Scalar::all(0);
         ^

My question is why is the first assignment correct while the second is not?

BrainabilGH
  • 464
  • 5
  • 15

1 Answers1

2

Declaration of Mat constructor which takes Vec<_Tp,n> as parameter is

  template<typename _Tp, int n>
  explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true);

cv::Scalar is treated as Vec<_Tp,4> so you can pass Scalar to Mat constructor in explicit way Class obj(parameter); not Class obj = parameter; so call

Mat test(Scalar::all(0));
rafix07
  • 20,001
  • 3
  • 20
  • 33