Ask Your Question
4

Why does "Scalar" mean "Vector"

asked Feb 21 '14

xaffeine gravatar image

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.

Preview: (hide)

Comments

nice question, waiting big_karma_guys )

Flart gravatar imageFlart (Feb 24 '14)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.

Rui Marques gravatar imageRui Marques (Feb 25 '14)edit

3 answers

Sort by » oldest newest most voted
1

answered Feb 23 '14

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 :)

Preview: (hide)

Comments

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

xaffeine gravatar imagexaffeine (Feb 24 '14)edit

Sorry xaffeine,I didnt get your comment.Could you please explain a bit more about your comment.

0

answered Feb 25 '14

solarblast gravatar image

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

Preview: (hide)
0

answered Feb 25 '14

xaffeine gravatar image

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.

Preview: (hide)

Question Tools

Stats

Asked: Feb 21 '14

Seen: 1,616 times

Last updated: Feb 25 '14