Please can some one explain the meaning of the four parameters of the cvScalar(double d, double d1, double d2, double d3) method in javacv?
How can I represent black color in cvScalar ?
The cvScalar is simply a convenient container for 1, 2, 3 or 4 floating point values.
The meaning of the data in such tuples is left to the user of the cvScalar.
For example they can be used to hold, say, Points in the plane (2-tuple), Rectangles (4-tuple), RGB colors (3-tuple), Points in a 3-D world (3-tuple) etc. The cvScalar is systematically implemented as a 4-tuple, with the unused values set to 0.
To answer the question about the RGB color black:
cvScalar cBlack = new cvScalar(0, 0, 0, 0);
// BEWARE: the params for the cvScalar constructor are not in RGB order
// it is: new cvScalar(blue, green, red, unused)
// note how the 4th scalar is unused.
Alternatively you can use the CV_RGB() convenience method as in:
CvScalar cBlack = CV_RGB(0, 0, 0);
// here the CV_RGB() arguments are in Red, Green, Blue order.
Edit: because the example above was for the color black, whereby all color components have the same value, it failed to make evident that the order of the RGB components as stored within the CvScalar is reverse from the conventional order Red, Green, Blue.
The CV_RGB()
convenience method's parameters are in the conventional RGB order, but the storage in the cvScalar is in Blue, Green, Red order.
In other words, the definition of CV_RGB is as follow:
public static CvScalar CV_RGB(double r, double g, double b) {
return cvScalar(b, g, r, 0);
}
Or said otherwise yet, cvScalar(0, 1, 130, 0)
is equivalent to CV_RGB(130, 1, 0)
, i.e. the color red, with a minute touch of green.
In addition to CV_RGB(), when using cvScalars for the purpose of color values, it may be convenient to use cvScalar.Red()
, cvScalar.Blue()
, cvScalar.Green()
methods to extract the individual components without having to worry where these are stored. The class also include a few static instances for each of the common colors: cvScalar.GRAY
, cvScalar.YELLOW
, cvScalar.BLUE
etc.