Mat parameters explained [closed]

asked 2017-07-08 08:02:47 -0600

arqam gravatar image

Mat object while printing in the string format as well as the values I have seen. But I would like to know what does this Scalar in Mat signifies for.

If we look in this line of code : Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3)); What does new Scalar(3) signifies for? I know for black image we put it as 0. So is the value here signifying 0-255 colors?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-11-13 13:34:29.837099

Comments

CV_8U is an unsigned char (0, 1, 2 ...255) and Scalar(3) all pixels values set to 3. In your example Mat objet is one row and one column so only one pixel set to 3. Mat object can be used for image, matrix ,feature...

LBerger gravatar imageLBerger ( 2017-07-08 08:17:48 -0600 )edit

@LeBerger So what if we set it as Scalar(0). What is that value actually, 0 or 3 in Scalar that we are passing?

arqam gravatar imagearqam ( 2017-07-08 08:24:12 -0600 )edit
1

It C++ but I think it could help you

Mat source = Mat(1, 1, CV_8U, Scalar(0));
cout << source << " with scalar(0)\n"; 
source = Mat(1, 1, CV_8U, Scalar(3));
cout << source << " with scalar(3)\n";
source = Mat(2, 1, CV_8UC(3), Scalar(3));
cout << source << " with scalar(3)\n";
source = Mat(2, 1, CV_8UC(3), Scalar::all(3));
cout << source << " with scalar::all(3)\n";

results

[  0] with scalar(0)
[  3] with scalar(3)
[  3,   0,   0;
   3,   0,   0] with scalar(3)
[  3,   3,   3;
   3,   3,   3] with scalar::all(3)

Scalar::all means all channels

"What is that value actually, 0 or 3 in Scalar that we are passing?" I'm not sure to understand

0 means black but if Mat is a histogram it means 0 occurence of this level

LBerger gravatar imageLBerger ( 2017-07-08 08:38:22 -0600 )edit