OpenCV标量数据类型,何时使用? [英] OpenCV scalar datatype, when to use?

查看:409
本文介绍了OpenCV标量数据类型,何时使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我们可以看看OpenCV的基本结构。我的问题是数据类型标量是什么,什么时候使用它。

Here we can hava a look on OpenCV's basic structures. My question is what exactly the datatype "scalar" is 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 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));

所以我的问题是为什么我不能使用 double 在这种情况下?或数组?

So my question is why can't i use double in this case? Or arrays?

提前感谢

推荐答案

=http://docs.opencv.org/2.4.2/modules/core/doc/basic_structures.html#Scalar_ =nofollow>标量是

A Scalar is a


从Vec导出的4元素向量的模板类。

Template class for a 4-element vector derived from Vec.

源自Vec< 4>,Scalar 和Scalar可以用作典型的4元素向量。 Scalar类型广泛用于OpenCV中传递像素值

Being derived from Vec<Tp, 4> , Scalar and Scalar can be used just as typical 4-element vectors. The type Scalar is widely used in OpenCV to pass pixel values.

您可以初始化 Mat 也不同,如:

You can initialize a Mat also differently, like:

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

将在内部转换为 Vec _ 。但由于 Mat 构造函数的签名接受 Scalar ,因此最好使用 Scalar

that will be internally converted to a Vec_. But since the signature of the Matconstructor accepts a Scalar, you better use a Scalar.

这将允许总是使用 Scalar 1到4个频道。

This will allow to use always the Scalar to pass pixel values for all images with 1 to 4 channels.

这篇关于OpenCV标量数据类型,何时使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆