opencv深入学习(2)--Scalar类型

CvScalar定义可存放1—4个数值的数值,其结构体如下:

typedef struct CvScalar
{
double val[4];
}CvScalar;

例如:CvScalar s;

如果使用的图像是1通道的,则s.val[0]中存储数据

如果使用的图像是3通道的,则s.val[0],s.val[1],s.val[2]中存储数据

cvGet2D 获得某个点的值, index0=height 行值, index1=width 列值。
CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 );
cvSet2D 给某个点赋值。
CVAPI(void) cvSet2D( CvArr* arr, int index0, int index1, CvScalar value );


 Scalar
• Represents a 4-element vector. The type Scalar is widely used in OpenCV for passing pixel values.
• In this tutorial, we will use it extensively to represent RGB color values (3 parameters). It is not necessary to
define the last argument if it is not going to be used.
• Let’s see an example, if we are asked for a color argument and we give:
Scalar( a, b, c )
We would be defining a RGB color such as: Red = c, Green = b and Blue = a

 

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;

 

你可能感兴趣的:(c,struct,存储,Class,Parameters)