Opencv Scalar_类表示是一维数组,只有4个元素,用于Opencv中传递像素值,如RGB颜色值。
Scalar_模板类构造函数,参数数量可以是0,1,2,3,4。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//////////////////////////////// Scalar_ /////////////////////////////// /** @brief Template class for a 4-element vector derived from Vec. Being derived from Vec\<_Tp, 4\> , Scalar\_ and Scalar can be used just as typical 4-element vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in OpenCV to pass pixel values. */ template<typename _Tp> class Scalar_ : public Vec<_Tp, 4> { public: //! default constructor Scalar_(); //参数数量 0 Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);//参数数量2,3,4都可以 Scalar_(_Tp v0); //参数数量 1 template<typename _Tp2, int cn> Scalar_(const Vec<_Tp2, cn>& v); //! returns a scalar with all elements set to v0 static Scalar_<_Tp> all(_Tp v0); //! conversion to another data type template<typename T2> operator Scalar_<T2>() const; //! per-element product Scalar_<_Tp> mul(const Scalar_<_Tp>& a, 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; //double类型 scalar,方便声明定义用 |
Scalar_类具体运用例子:
1 2 3 4 |
Mat Img1(200, 200, CV_8U, Scalar(0)); Mat Img2(200, 200, CV_8UC3, Scalar(255, 0, 0)); imshow("白色图像",Img1); imshow("蓝色图像",Img2); |
Scalar_类使用测试结果: