OpenCV scalar data type, when to use?

Here we can take a look at the basic structures of OpenCV. My question is what exactly is the scalar data type and when do I use it.

Here you can see its definition:

template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
{
public:
//! various constructors
Scalar_();
Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
Scalar_(const CvScalar& s);
Scalar_(_Tp v0);

//! returns a scalar with all elements set to v0
static Scalar_<_Tp> all(_Tp v0);
//! conversion to the old-style CvScalar
operator CvScalar() const;

//! conversion to another data type
template<typename T2> operator Scalar_<T2>() const;

//! per-element product
Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;

// returns (v0, -v1, -v2, -v3)
Scalar_<_Tp> conj() const;

// returns true iff v1 == v2 == v3 == 0
bool isReal() const;
};

typedef Scalar_<double> Scalar;

Here you can see an example of how they use it.

// make a 7x7 complex matrix filled with 1+3j.
Mat M(7,7,CV_32FC2,Scalar(1,3));
// and now turn M to a 100x60 15-channel 8-bit matrix.
// The old content will be deallocated
M.create(100,60,CV_8UC(15));

So my question is: why can't I use doublein this case? Or arrays?

Thank you in advance

+4
source share
1 answer

A Scalar is

The template class for a 4-element vector derived from Vec.

Vec < Tp, 4 > , 4- . Scalar OpenCV .

Mat , :

Mat img(10, 10, CV_32FC2, { 2, 3 });

Vec_. Mat Scalar, Scalar.

Scalar 1 4 .

+2

Source: https://habr.com/ru/post/1609786/


All Articles