ImageSimulator

class ImageSimulator(*args, **kwargs)

Bases: pybind11_object

Class which enables to project an image in the 3D space and get the view of a virtual camera.

The image is represented by a rectangular image whose corners coordinates are known in the 3D frame linked to the 3D rectangle.

The 3D rectangle is positionned relative to a virtual camera (represented by its intrinsic parameters). Indeed, the pose \(cMt\) has to be given by the user of the class.

And finally, the view of the virtual camera is given by the geImage() method.

You can use a colored or a gray scaled image.

To avoid the aliasing especially when the camera is very near from the image plane, a bilinear interpolation can be done for every pixels which have to be filled in. By default this functionality is not used because it consumes lot of time.

The following example explain how to use the class.

#include <visp3/core/vpImage.h>
#include <visp3/robot/vpImageSimulator.h>

int main()
{
  vpImage<vpRGBa> Icamera(480,640,0);
  vpImage<vpRGBa> Iimage(60,60);

  // Initialise the image which will be projected into the image Icamera
  vpRGBa colorb(0,0,255);
  vpRGBa colorw(255,255,255);
  vpRGBa colorr(255,0,0);
  for(int i = 0; i < 60; i++)
  {
    for(int j = 0; j < 20; j++)
      Iimage[i][j] = colorb;
    for(int j = 20; j < 40; j++)
      Iimage[i][j] = colorw;
    for(int j = 40; j < 60; j++)
      Iimage[i][j] = colorr;
  }

  // Initialise the 3D coordinates of the Iimage corners
  vpColVector X[4];
  for (int i = 0; i < 4; i++) X[i].resize(3);
  // Top left corner
  X[0][0] = -1;
  X[0][1] = -1;
  X[0][2] = 0;

  // Top right corner
  X[1][0] = 1;
  X[1][1] = -1;
  X[1][2] = 0;

  // Bottom right corner
  X[2][0] = 1;
  X[2][1] = 1;
  X[2][2] = 0;

  //Bottom left corner
  X[3][0] = -1;
  X[3][1] = 1;
  X[3][2] = 0;

  vpImageSimulator sim;
  sim.init(Iimage, X);

  sim.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(60),vpMath::rad(0),0));

  vpCameraParameters cam(868.0, 869.0, 320, 240);

  sim.getImage(Icamera,cam);

  return 0;
}

Overloaded function.

  1. __init__(self: visp._visp.robot.ImageSimulator, col: visp._visp.robot.ImageSimulator.ColorPlan = COLORED) -> None

  2. __init__(self: visp._visp.robot.ImageSimulator, text: visp._visp.robot.ImageSimulator) -> None

Copy constructor

Methods

__init__

Overloaded function.

get3DcornersTextureRectangle

getImage

Overloaded function.

getImageMultiplePlanes

Overloaded function.

init

Overloaded function.

setBackGroundTexture

This function allows to set the background to a texture instead of the default black background.

setCameraPosition

Enable to set the position of the 3D plane relative to the virtual camera.

setCleanPreviousImage

As it can be time consuming to reset all the image to a default baground value, this function enable to reset only the pixel which changed the previous time.

setInterpolationType

Inherited Methods

Operators

__doc__

__init__

Overloaded function.

__module__

__repr__

Attributes

BILINEAR_INTERPOLATION

COLORED

GRAY_SCALED

SIMPLE

__annotations__

class ColorPlan(self, value: int)

Bases: pybind11_object

Values:

  • SIMPLE

  • BILINEAR_INTERPOLATION

__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 InterpolationType(self, value: int)

Bases: pybind11_object

Values:

  • SIMPLE

  • BILINEAR_INTERPOLATION

__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
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.robot.ImageSimulator, col: visp._visp.robot.ImageSimulator.ColorPlan = COLORED) -> None

  2. __init__(self: visp._visp.robot.ImageSimulator, text: visp._visp.robot.ImageSimulator) -> None

Copy constructor

get3DcornersTextureRectangle(self) list[visp._visp.core.ColVector]
getImage(*args, **kwargs)

Overloaded function.

  1. getImage(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageGray, cam: visp._visp.core.CameraParameters) -> None

Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay!

Parameters:
I

The image used to store the result.

cam

The parameters of the virtual camera.

  1. getImage(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageRGBa, cam: visp._visp.core.CameraParameters) -> None

Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay!

Parameters:
I

The image used to store the result.

cam

The parameters of the virtual camera.

  1. getImage(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageGray, Isrc: visp._visp.core.ImageGray, cam: visp._visp.core.CameraParameters) -> None

Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay! In this method you specify directly the image which is projected.

Parameters:
I

The image used to store the result.

Isrc

The image which is projected into \(I\) .

cam

The parameters of the virtual camera.

  1. getImage(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageRGBa, Isrc: visp._visp.core.ImageRGBa, cam: visp._visp.core.CameraParameters) -> None

Get the view of the virtual camera. Be carefull, the image I is modified. The projected image is not added as an overlay! In this method you specify directly the image which is projected.

Parameters:
I

The image used to store the result.

Isrc

The image which is projected into \(I\) .

cam

The parameters of the virtual camera.

  1. getImage(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageGray, cam: visp._visp.core.CameraParameters, zBuffer: visp._visp.core.Matrix) -> None

Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay!

To take into account the projection of several images, a matrix \(zBuffer\) is given as argument. This matrix contains the z coordinates of all the pixel of the image \(I\) in the camera frame. During the projection, the pixels are updated if there is no other plan between the camera and the projected image. The matrix \(zBuffer\) is updated in this case.

Parameters:
I

The image used to store the result.

cam

The parameters of the virtual camera.

zBuffer

A matrix containing the z coordinates of the pixels of the image \(I\)

  1. getImage(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageRGBa, cam: visp._visp.core.CameraParameters, zBuffer: visp._visp.core.Matrix) -> None

Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay!

To take into account the projection of several images, a matrix \(zBuffer\) is given as argument. This matrix contains the z coordinates of all the pixel of the image \(I\) in the camera frame. During the projection, the pixels are updated if there is no other plan between the camera and the projected image. The matrix \(zBuffer\) is updated in this case.

Parameters:
I

The image used to store the result.

cam

The parameters of the virtual camera.

zBuffer

A matrix containing the z coordinates of the pixels of the image \(I\)

static getImageMultiplePlanes(*args, **kwargs)

Overloaded function.

  1. getImageMultiplePlanes(I: visp._visp.core.ImageGray, list: list[visp._visp.robot.ImageSimulator], cam: visp._visp.core.CameraParameters) -> None

Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay! With this method, a list of image is projected into the image. Thus, you have to initialise a list of vpImageSimulator . Then you store them into a vpList . And finally with this method you project them into the image \(I\) . The depth of the 3D scene is managed such as an image in foreground hides an image background.

The following example shows how to use the method:

#include <list>
#include <visp3/core/vpImage.h>
#include <visp3/robot/vpImageSimulator.h>

int main()
{
  vpImage<vpRGBa> Icamera(480,640,0);
  vpImage<vpRGBa> Iimage(60,60);

  // Initialise the image which will be projected into the image Icamera
  vpRGBa colorb(0,0,255);
  vpRGBa colorw(255,255,255);
  vpRGBa colorr(255,0,0);
  for(int i = 0; i < 60; i++)
  {
    for(int j = 0; j < 20; j++)
      Iimage[i][j] = colorb;
    for(int j = 20; j < 40; j++)
      Iimage[i][j] = colorw;
    for(int j = 40; j < 60; j++)
      Iimage[i][j] = colorr;
  }

  // Initialise the 3D coordinates of the Iimage corners
  vpColVector X[4];
  for (int i = 0; i < 4; i++) X[i].resize(3);
  // Top left corner
  X[0][0] = -1;
  X[0][1] = -1;
  X[0][2] = 1;

  // Top right corner
  X[1][0] = 1;
  X[1][1] = -1;
  X[1][2] = 1;

  // Bottom right corner
  X[2][0] = 1;
  X[2][1] = 1;
  X[2][2] = 1;

  //Bottom left corner
  X[3][0] = -1;
  X[3][1] = 1;
  X[3][2] = 1;

  vpImageSimulator sim;
  sim.init(Iimage, X);

  // Top left corner
  X[0][0] = -1;
  X[0][1] = -1;
  X[0][2] = 1;

  // Top right corner
  X[1][0] = 1;
  X[1][1] = -1;
  X[1][2] = 1;

  // Bottom right corner
  X[2][0] = 1;
  X[2][1] = 1;
  X[2][2] = 1;

  //Bottom left corner
  X[3][0] = -1;
  X[3][1] = 1;
  X[3][2] = 1;

  vpImageSimulator sim2;
  sim2.init(Iimage, X);

  sim.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(0),vpMath::rad(30),0));
  sim2.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(0),vpMath::rad(-30),0));

  std::list<vpImageSimulator> listSim;
  listSim.addRight(sim);
  listSim.addRight(sim2);

  sim.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(60),vpMath::rad(0),0));

  vpCameraParameters cam(868.0, 869.0, 320, 240);

  vpImageSimulator::getImage(Icamera,listSim,cam);

  return 0;
}
Parameters:
I

The image used to store the result

list

List of vpImageSimulator to project

cam

The parameters of the virtual camera

  1. getImageMultiplePlanes(I: visp._visp.core.ImageRGBa, list: list[visp._visp.robot.ImageSimulator], cam: visp._visp.core.CameraParameters) -> None

Get the view of the virtual camera. Be carefull, the image I is modified. The projected image is not added as an overlay!

With this method, a list of image is projected into the image. Thus, you have to initialise a list of vpImageSimulator . Then you store them into a vpList . And finally with this method you project them into the image \(I\) . The depth of the 3D scene is managed such as an image in foreground hides an image background.

The following example shows how to use the method:

#include <list>
#include <visp3/core/vpImage.h>
#include <visp3/robot/vpImageSimulator.h>

int main()
{
  vpImage<vpRGBa> Icamera(480,640,0);
  vpImage<vpRGBa> Iimage(60,60);

  // Initialise the image which will be projected into the image Icamera
  vpRGBa colorb(0,0,255);
  vpRGBa colorw(255,255,255);
  vpRGBa colorr(255,0,0);
  for(int i = 0; i < 60; i++)
  {
    for(int j = 0; j < 20; j++)
      Iimage[i][j] = colorb;
    for(int j = 20; j < 40; j++)
      Iimage[i][j] = colorw;
    for(int j = 40; j < 60; j++)
      Iimage[i][j] = colorr;
  }

  // Initialise the 3D coordinates of the Iimage corners
  vpColVector X[4];
  for (int i = 0; i < 4; i++) X[i].resize(3);
  // Top left corner
  X[0][0] = -1;
  X[0][1] = -1;
  X[0][2] = 1;

  // Top right corner
  X[1][0] = 1;
  X[1][1] = -1;
  X[1][2] = 1;

  // Bottom right corner
  X[2][0] = 1;
  X[2][1] = 1;
  X[2][2] = 1;

  //Bottom left corner
  X[3][0] = -1;
  X[3][1] = 1;
  X[3][2] = 1;

  vpImageSimulator sim;
  sim.init(Iimage, X);

  // Top left corner
  X[0][0] = -1;
  X[0][1] = -1;
  X[0][2] = 1;

  // Top right corner
  X[1][0] = 1;
  X[1][1] = -1;
  X[1][2] = 1;

  // Bottom right corner
  X[2][0] = 1;
  X[2][1] = 1;
  X[2][2] = 1;

  //Bottom left corner
  X[3][0] = -1;
  X[3][1] = 1;
  X[3][2] = 1;

  vpImageSimulator sim2;
  sim2.init(Iimage, X);

  sim.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(0),vpMath::rad(30),0));
  sim2.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(0),vpMath::rad(-30),0));

  std::list<vpImageSimulator> listSim;
  listSim.addRight(sim);
  listSim.addRight(sim2);

  sim.setCameraPosition(vpHomogeneousMatrix(0,0,5,vpMath::rad(60),vpMath::rad(0),0));

  vpCameraParameters cam(868.0, 869.0, 320, 240);

  vpImageSimulator::getImage(Icamera,listSim,cam);

  return 0;
}
Parameters:
I

The image used to store the result

list

List of vpImageSimulator to project

cam

The parameters of the virtual camera

init(*args, **kwargs)

Overloaded function.

  1. init(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageGray, X: list[visp._visp.core.Point]) -> None

Initialise the image thanks to an image \(I\) and a table of vector containing the 3D coordinates of the image’s corners.

  • \(X[0]\) :Top left corner.

  • \(X[1]\) :Top right corner.

  • \(X[2]\) :Bottom right corner.

  • \(X[3]\) :Bottom left corner.

Parameters:
I

The image which is projected.

  1. init(self: visp._visp.robot.ImageSimulator, I: visp._visp.core.ImageRGBa, X: list[visp._visp.core.Point]) -> None

Initialise the image thanks to an image \(I\) and a table of vector containing the 3D coordinates of the image’s corners.

  • \(X[0]\) :Top left corner.

  • \(X[1]\) :Top right corner.

  • \(X[2]\) :Bottom right corner.

  • \(X[3]\) :Bottom left corner.

Parameters:
I

The image which is projected.

  1. init(self: visp._visp.robot.ImageSimulator, file_image: str, X: list[visp._visp.core.Point]) -> None

Initialise the image thanks to an image whose adress is given by \(file_image\) and a table of vector containing the 3D coordinates of the image’s corners.

  • \(X[0]\) :Top left corner.

  • \(X[1]\) :Top right corner.

  • \(X[2]\) :Bottom right corner.

  • \(X[3]\) :Bottom left corner.

Parameters:
file_image

The adress of an image file.

setBackGroundTexture(self, Iback: visp._visp.core.ImageGray) None

This function allows to set the background to a texture instead of the default black background.

Parameters:
Iback: visp._visp.core.ImageGray

Image/Texture for the background

setCameraPosition(self, cMt: visp._visp.core.HomogeneousMatrix) None

Enable to set the position of the 3D plane relative to the virtual camera.

setCleanPreviousImage(self: visp._visp.robot.ImageSimulator, clean: bool, color: visp._visp.core.Color = vpColor::white) None

As it can be time consuming to reset all the image to a default baground value, this function enable to reset only the pixel which changed the previous time.

By default this functionality is disabled. and the background color is white.

Parameters:
clean

Enable the reset method.

color

Color of the back ground.

setInterpolationType(self, interplt: visp._visp.robot.ImageSimulator.InterpolationType) None