Ask Your Question
4

Why does "Scalar" mean "Vector"

asked 2014-02-21 13:57:19 -0500

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.

edit retag flag offensive close merge delete

Comments

nice question, waiting big_karma_guys )

Flart gravatar imageFlart ( 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.

Rui Marques gravatar imageRui Marques ( 2014-02-25 13:52:38 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
1

answered 2014-02-23 13:41:58 -0500

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

edit flag offensive delete link more

Comments

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

xaffeine gravatar imagexaffeine ( 2014-02-24 12:53:53 -0500 )edit

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

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-24 13:05:14 -0500 )edit
0

answered 2014-02-25 13:05:27 -0500

solarblast gravatar image

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

edit flag offensive delete link more
0

answered 2014-02-25 12:57:53 -0500

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-02-21 13:57:19 -0500

Seen: 596 times

Last updated: Feb 25 '14