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;

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值