Color

class Color(*args, **kwargs)

Bases: RGBa

Class to define RGB colors available for display functionalities.

  • You may use predefined colors:

    • vpColor::black , vpColor::white ,

    • vpColor::lightGray , vpColor::gray , vpColor::darkGray ,

    • vpColor::lightRed , vpColor::red , vpColor::darkRed ,

    • vpColor::lightGreen , vpColor::green , vpColor::darkGreen ,

    • vpColor::lightBlue , vpColor::blue , vpColor::darkBlue ,

    • vpColor::yellow , vpColor::cyan , vpColor::orange , vpColor::purple

      vpColor color1(vpColor::lightGreen);
      vpColor color2 = vpColor::lightGreen;
      
  • or specify your own color by settings its R,G,B values.

    unsigned char R=140, G=255, B=140;
    vpColor color1(R, G, B);
    vpColor color2;
    color2.setColor(R, G, B);
    

Warning

Since ViSP 3.3.1 or higher we introduce the alpha channel support for color transparency. This feature is for the moment only supported using vpDisplayOpenCV . To use transparency you may set an additional alpha parameter. When the value is 255, there is no transparency. A value equal to 0 means that the color is completely transparent. The following examples show how to introduce transparency:

  • using predefined colors:

    unsigned char alpha = 128;
    vpColor color1(vpColor::lightGreen, alpha);
    vpColor color2 = vpColor(vpColor::lightGreen, alpha);
    
  • or using user defined colors:

    unsigned char R=140, G=255, B=140, alpha=128;
    vpColor color1(R, G, B, alpha);
    vpColor color2;
    color2.setColor(R, G, B, alpha);
    

See displayOpenCV.cpp example for complete usage when displaying filled transparent circles or rectangles.

An identifier vpColor::vpColorIdentifier is associated to each color. This identifier is useful to determine if a color is predefined or specified by it R,G,B values. In that last case, the identifier is always set to vpColor::id_unknown .

The example below shows how to display geometric features in a display overlay using predefined colors (here the blue color to draw a circle) and a specific brown color (used to draw a rectangle).

#include <visp3/gui/vpDisplayD3D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>

int main()
{
  vpImage<unsigned char> I(240, 320); // Create a black grey level image

  vpDisplay *d;

  // Depending on the detected third party libraries, we instantiate here the
  // first video device which is available
#if defined(VISP_HAVE_X11)
  d = new vpDisplayX;
#elif defined(VISP_HAVE_GTK)
  d = new vpDisplayGTK;
#elif defined(VISP_HAVE_GDI)
  d = new vpDisplayGDI;
#elif defined(VISP_HAVE_D3D9)
  d = new vpDisplayD3D;
#elif defined(HAVE_OPENCV_HIGHGUI)
  d = new vpDisplayOpenCV;
#endif

  // Initialize the display with the image I. Display and image are
  // now link together.
#ifdef VISP_HAVE_DISPLAY
  d->init(I);
#endif

  // Set the display background with image I content
  vpDisplay::display(I);

  // Draw a filled circle with the predefined blue color
  vpDisplay::displayCircle(I, 100, 200, 30, vpColor::blue, true);

  // Creation of a new brown color with its RGB values
  vpColor color(128, 100, 50);

  // Draw a brown rectangle in the display overlay (foreground)
  vpDisplay::displayRectangle(I, 10, 10, 100, 20, color, true);

  // Flush the foreground and background display
  vpDisplay::flush(I);

  delete d;
}

Overloaded function.

  1. __init__(self: visp._visp.core.Color) -> None

Default constructor. All the colors components are set to zero.

The color identifier is set to vpColor::id_unknown to indicate that this color is not a predefined one.

  1. __init__(self: visp._visp.core.Color, r: int, g: int, b: int, cid: visp._visp.core.Color.ColorIdentifier) -> None

Construct a color from its RGB values.

Parameters:
r

Red component.

g

Green component.

b

Blue component.

cid

The color identifier to indicate if this color is or not a predefined one.

  1. __init__(self: visp._visp.core.Color, r: int, g: int, b: int, alpha: int, cid: visp._visp.core.Color.ColorIdentifier) -> None

Construct a color from its RGB values and alpha channel.

Parameters:
r

Red component.

g

Green component.

b

Blue component.

alpha

Alpha channel for transparency.

cid

The color identifier to indicate if this color is or not a predefined one.

  1. __init__(self: visp._visp.core.Color, color: visp._visp.core.Color, alpha: int) -> None

Construct a color with an alpha channel.

Parameters:
color

RGB color.

alpha

Alpha channel for transparency.

Methods

__init__

Overloaded function.

getColor

Get a predefined color

setColor

Set a color from its RGB values.

Inherited Methods

R

AlphaDefault

Values:

G

A

B

alpha_default

Operators

__doc__

__init__

Overloaded function.

__module__

Attributes

A

B

G

R

__annotations__

__hash__

alpha_default

black

blue

cyan

darkBlue

darkGray

darkGreen

darkRed

gray

green

id

id_black

id_blue

id_cyan

id_darkBlue

id_darkGray

id_darkGreen

id_darkRed

id_gray

id_green

id_lightBlue

id_lightGray

id_lightGreen

id_lightRed

id_orange

id_purple

id_red

id_unknown

id_white

id_yellow

lightBlue

lightGray

lightGreen

lightRed

nbColors

none

orange

purple

red

white

yellow

class AlphaDefault(self, value: int)

Bases: pybind11_object

Values:

  • alpha_default

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
class ColorIdentifier(self, value: int)

Bases: pybind11_object

Predefined colors identifier.

Values:

  • id_black: Identifier associated to the predefined vpColor::black color.

  • id_white: Identifier associated to the predefined vpColor::white color.

  • id_lightGray: Identifier associated to the predefined vpColor::lightGray color.

  • id_gray: Identifier associated to the predefined vpColor::gray color.

  • id_darkGray: Identifier associated to the predefined vpColor::darkGray color.

  • id_lightRed: Identifier associated to the predefined vpColor::lightRed color.

  • id_red: Identifier associated to the predefined vpColor::red color.

  • id_darkRed: Identifier associated to the predefined vpColor::darkRed color.

  • id_lightGreen: Identifier associated to the predefined vpColor::lightGreen color.

  • id_green: Identifier associated to the predefined vpColor::green color.

  • id_darkGreen: Identifier associated to the predefined vpColor::darkGreen color.

  • id_lightBlue: Identifier associated to the predefined vpColor::lightBlue color.

  • id_blue: Identifier associated to the predefined vpColor::blue color.

  • id_darkBlue: Identifier associated to the predefined vpColor::darkBlue color.

  • id_yellow: Identifier associated to the predefined vpColor::yellow color.

  • id_cyan: Identifier associated to the predefined vpColor::cyan color.

  • id_orange: Identifier associated to the predefined vpColor::orange color.

  • id_purple: Identifier associated to the predefined vpColor::purple color.

  • id_unknown: Identifier associated to unknowned colors. By unknowned, we mean not a predefined color. This identifier can also be used to know the number of predefined colors.

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
__add__(*args, **kwargs)

Overloaded function.

  1. __add__(self: visp._visp.core.RGBa, v: visp._visp.core.RGBa) -> visp._visp.core.RGBa

Warning

in case of overflow : e.g. 128+128 returns 0 for all 4 channels

Parameters:
v

Color to add to the current object “this”.

Returns:

“this” + v

  1. __add__(self: visp._visp.core.RGBa, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector

Parameters:
v

Color to add to the current object “this”.

Returns:

“this” + v

__eq__(self, v: visp._visp.core.RGBa) bool

Compare two RGBa values.

Returns:

true if the values are the same, false otherwise.

__gt__(self, v: visp._visp.core.RGBa) bool
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.core.Color) -> None

Default constructor. All the colors components are set to zero.

The color identifier is set to vpColor::id_unknown to indicate that this color is not a predefined one.

  1. __init__(self: visp._visp.core.Color, r: int, g: int, b: int, cid: visp._visp.core.Color.ColorIdentifier) -> None

Construct a color from its RGB values.

Parameters:
r

Red component.

g

Green component.

b

Blue component.

cid

The color identifier to indicate if this color is or not a predefined one.

  1. __init__(self: visp._visp.core.Color, r: int, g: int, b: int, alpha: int, cid: visp._visp.core.Color.ColorIdentifier) -> None

Construct a color from its RGB values and alpha channel.

Parameters:
r

Red component.

g

Green component.

b

Blue component.

alpha

Alpha channel for transparency.

cid

The color identifier to indicate if this color is or not a predefined one.

  1. __init__(self: visp._visp.core.Color, color: visp._visp.core.Color, alpha: int) -> None

Construct a color with an alpha channel.

Parameters:
color

RGB color.

alpha

Alpha channel for transparency.

__lt__(self, v: visp._visp.core.RGBa) bool
__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: visp._visp.core.RGBa, v: float) -> visp._visp.core.ColVector

Parameters:
v

Value to multiply.

Returns:

v * “this”

  1. __mul__(self: visp._visp.core.RGBa, v: float) -> visp._visp.core.ColVector

Parameters:
v

Value to multiply.

Returns:

v * “this”

__ne__(self, v: visp._visp.core.RGBa) bool

Compare two color pixels.

Returns:

true if the images are different, false if they are the same.

__sub__(*args, **kwargs)

Overloaded function.

  1. __sub__(self: visp._visp.core.RGBa, v: visp._visp.core.RGBa) -> visp._visp.core.ColVector

Parameters:
v

Color to subtract to the current object “this”.

Returns:

“this” - v

  1. __sub__(self: visp._visp.core.RGBa, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector

Parameters:
v

Color to subtract to the current object “this”.

Returns:

“this” - v

static getColor(i: int) visp._visp.core.Color

Get a predefined color

Parameters:
i: int

color indice

setColor(self, r: int, g: int, b: int, a: int) None

Set a color from its RGB values.

The color identifier is set to vpColor::id_unknown to indicate that this color is not a predefined one.

Parameters:
r: int

Red component.

g: int

Green component.

b: int

Blue component.

a: int

Alpha component for transparency.

__hash__ = None