Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the cv::Scalar type mean?

Tags:

c++

opencv

I have to find the sum of the elements in a Mat, the sum function of OpenCV returns a cv::Scalar but how should I interpret it ?

like image 681
huehuehuehue Avatar asked Nov 08 '14 15:11

huehuehuehue


People also ask

What does scalar do in OpenCV?

Scalar Represents a 4-element vector. The type Scalar is widely used in OpenCV for passing pixel values. In this tutorial, we will use it extensively to represent BGR color values (3 parameters). It is not necessary to define the last argument if it is not going to be used.

What is a Scalar type in c++?

Data objects in C++ can be categorized as either scalar (e.g. integers and pointers) or non- scalar (e.g. arrays and classes), where scalars are primitive objects which contain a single value and are not composed of other C++ objects.

What is Vec3b OpenCV?

Vec3b is the abbreviation for "vector with 3 byte entries" Here those byte entries are unsigned char values to represent values between 0 .. 255. Each byte typically represents the intensity of a single color channel, so on default, Vec3b is a single RGB (or better BGR) pixel.


1 Answers

cv::Scalar is used because the image can be multi-channel. For this reason the the white color is represented as:

cv::Scalar(255,255,255);

For access a particular element you can simply use [] operator:

cv::Scalar myWhite(255,255,255);
cout << myWhite[0] << endl;

For the sum, each channel will represent the sum of that particular channel.

like image 103
dynamic Avatar answered Oct 03 '22 01:10

dynamic