Here我们可以了解一下OpenCV的基本结构。我的问题是究竟是什么数据类型"标量"我什么时候使用它。
在这里你可以看到它的定义:
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;
在这里,您可以看到他们如何使用它的示例
// 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
?还是阵列?
提前致谢
答案 0 :(得分:2)
从Vec派生的4元素向量的模板类。
源自Vec&lt; Tp,4&gt; ,Scalar 和Scalar可以用作典型的4元素向量。 Scalar类型在OpenCV中广泛用于传递像素值。
您也可以采用不同的方式初始化Mat
,例如:
Mat img(10, 10, CV_32FC2, { 2, 3 });
将在内部转换为Vec_
。但由于Mat
构造函数的签名接受Scalar
,因此最好使用Scalar
。
这将允许始终使用Scalar
为1到4个通道的所有图像传递像素值。