Why does "Scalar" mean "Vector"

Why does OpenCV use the name Scalar to mean a 4-element vector. In mathematics, a scalar and a vector are two different things, unless you are talking about a 1-element vector.

edit retag close merge delete

nice question, waiting big_karma_guys )

( 2014-02-24 04:41:41 -0500 )edit

I use mostly opencv android but I think Scalar appears in the same situations. The usage of Scalar there looks more like a tuple, usually with 3 or 4 elements.

( 2014-02-25 13:52:38 -0500 )edit

Sort by ยป oldest newest most voted

Hi friends,

vector types also exist for 2-element and 4-element vectors (cv::Vec2b and cv::Vec4b) and for other element types. In this later case, the last letter is replaced by s for short, i for int, f for float, and d for double. All of these types are defined using the template class cv::Vec<t,n> where T is the type and N is the number of vector elements.

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.

Thus Scalar does not literally mean Vector.

Hope this helps you :)

more

Thus "Scalar" does literally mean Vector of a certain size.

( 2014-02-24 12:53:53 -0500 )edit

( 2014-02-24 13:05:14 -0500 )edit

A scalar is a number. A vector can be any tuple, (1,3),(4,8,20,6). ...

more

It seems the answer must be "for historical reasons." If I were king, I would change Scalar to something like Vec4d and Scalar_ to something like Vec4_ (though I don't know why the underscore is there).

I think this would lead to less confusion over time.

more