Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpImageSimulator Class Reference

#include <vpImageSimulator.h>

Public Types

enum  vpColorPlan { COLORED , GRAY_SCALED }
enum  vpInterpolationType { SIMPLE , BILINEAR_INTERPOLATION }

Public Member Functions

VP_EXPLICIT vpImageSimulator (const vpColorPlan &col=COLORED)
 vpImageSimulator (const vpImageSimulator &text)
virtual ~vpImageSimulator ()
vpImageSimulatoroperator= (const vpImageSimulator &sim)
void init (const vpImage< unsigned char > &I, vpColVector *X)
void init (const vpImage< vpRGBa > &I, vpColVector *X)
void init (const char *file_image, vpColVector *X)
void init (const vpImage< unsigned char > &I, const std::vector< vpPoint > &X)
void init (const vpImage< vpRGBa > &I, const std::vector< vpPoint > &X)
void init (const char *file_image, const std::vector< vpPoint > &X)
void setCameraPosition (const vpHomogeneousMatrix &cMt)
void setInterpolationType (const vpInterpolationType interplt)
void getImage (vpImage< unsigned char > &I, const vpCameraParameters &cam)
void getImage (vpImage< vpRGBa > &I, const vpCameraParameters &cam)
void getImage (vpImage< unsigned char > &I, vpImage< unsigned char > &Isrc, const vpCameraParameters &cam)
void getImage (vpImage< vpRGBa > &I, vpImage< vpRGBa > &Isrc, const vpCameraParameters &cam)
void getImage (vpImage< unsigned char > &I, const vpCameraParameters &cam, vpMatrix &zBuffer)
void getImage (vpImage< vpRGBa > &I, const vpCameraParameters &cam, vpMatrix &zBuffer)
std::vector< vpColVectorget3DcornersTextureRectangle ()
void setCleanPreviousImage (const bool &clean, const vpColor &color=vpColor::white)
void setBackGroundTexture (const vpImage< unsigned char > &Iback)

Static Public Member Functions

static void getImage (vpImage< unsigned char > &I, std::list< vpImageSimulator > &list, const vpCameraParameters &cam)
static void getImage (vpImage< vpRGBa > &I, std::list< vpImageSimulator > &list, const vpCameraParameters &cam)

Friends

VISP_EXPORT std::ostream & operator<< (std::ostream &os, const vpImageSimulator &)

Detailed Description

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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
vpImage<vpRGBa> Icamera(480,640,vpRGBa(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
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;
sim.init(Iimage, X);
vpCameraParameters cam(868.0, 869.0, 320, 240);
sim.getImage(Icamera,cam);
return 0;
}
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class which enables to project an image in the 3D space and get the view of a virtual camera.
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
void init(const vpImage< unsigned char > &I, vpColVector *X)
void setCameraPosition(const vpHomogeneousMatrix &cMt)
Definition of the vpImage class member functions.
Definition vpImage.h:131
static double rad(double deg)
Definition vpMath.h:129

Tutorials
If you are interested in projecting an image in the 3D space and getting the view of a virtual camera, you may have a look at:

Examples
photometricMappingVisualServoing.cpp, photometricVisualServoing.cpp, photometricVisualServoingWithoutVpServo.cpp, servoSimu4Points.cpp, tutorial-ibvs-4pts-image-tracking.cpp, and tutorial-image-simulator.cpp.

Definition at line 150 of file vpImageSimulator.h.

Member Enumeration Documentation

◆ vpColorPlan

Enumerator
COLORED 
GRAY_SCALED 

Definition at line 153 of file vpImageSimulator.h.

◆ vpInterpolationType

Enumerator
SIMPLE 
BILINEAR_INTERPOLATION 

Definition at line 155 of file vpImageSimulator.h.

Constructor & Destructor Documentation

◆ vpImageSimulator() [1/2]

BEGIN_VISP_NAMESPACE vpImageSimulator::vpImageSimulator ( const vpColorPlan & col = COLORED)

Basic constructor.

You can choose if you want to use a colored or gray scaled image.

Parameters
col: Enable to choose the color space to use for the image which is projected.

By default the class uses colored images.

Definition at line 57 of file vpImageSimulator.cpp.

References SIMPLE.

Referenced by getImage(), getImage(), operator<<, operator=(), and vpImageSimulator().

◆ vpImageSimulator() [2/2]

vpImageSimulator::vpImageSimulator ( const vpImageSimulator & text)

Copy constructor

Definition at line 94 of file vpImageSimulator.cpp.

References GRAY_SCALED, vpImage< Type >::resize(), setCameraPosition(), SIMPLE, and vpImageSimulator().

◆ ~vpImageSimulator()

vpImageSimulator::~vpImageSimulator ( )
virtual

Basic destructor.

Definition at line 143 of file vpImageSimulator.cpp.

Member Function Documentation

◆ get3DcornersTextureRectangle()

std::vector< vpColVector > vpImageSimulator::get3DcornersTextureRectangle ( )

Definition at line 1540 of file vpImageSimulator.cpp.

◆ getImage() [1/8]

void vpImageSimulator::getImage ( vpImage< unsigned char > & I,
const vpCameraParameters & cam )

◆ getImage() [2/8]

void vpImageSimulator::getImage ( vpImage< unsigned char > & I,
const vpCameraParameters & cam,
vpMatrix & zBuffer )

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 $

Definition at line 304 of file vpImageSimulator.cpp.

References vpRGBa::B, COLORED, vpPixelMeterConversion::convertPoint(), vpRGBa::G, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), GRAY_SCALED, vpMatrixException::incorrectMatrixSizeError, vpRGBa::R, and vpImagePoint::set_ij().

◆ getImage() [3/8]

void vpImageSimulator::getImage ( vpImage< unsigned char > & I,
std::list< vpImageSimulator > & list,
const vpCameraParameters & cam )
static

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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
vpImage<vpRGBa> Icamera(480, 640, vpRGBa(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
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;
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;
sim2.init(Iimage, X);
std::list<vpImageSimulator> listSim;
listSim.addRight(sim);
listSim.addRight(sim2);
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

Definition at line 655 of file vpImageSimulator.cpp.

References vpRGBa::B, COLORED, vpPixelMeterConversion::convertPoint(), vpRGBa::G, vpRect::getBottom(), vpRect::getLeft(), vpRect::getRight(), vpRect::getTop(), GRAY_SCALED, vpRGBa::R, vpImagePoint::set_ij(), and vpImageSimulator().

◆ getImage() [4/8]

void vpImageSimulator::getImage ( vpImage< unsigned char > & I,
vpImage< unsigned char > & Isrc,
const vpCameraParameters & cam )

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.

Definition at line 249 of file vpImageSimulator.cpp.

References vpPixelMeterConversion::convertPoint(), and vpImagePoint::set_ij().

◆ getImage() [5/8]

void vpImageSimulator::getImage ( vpImage< vpRGBa > & I,
const vpCameraParameters & cam )

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.

Definition at line 371 of file vpImageSimulator.cpp.

References vpRGBa::B, COLORED, vpPixelMeterConversion::convertPoint(), vpRGBa::G, GRAY_SCALED, vpRGBa::R, and vpImagePoint::set_ij().

◆ getImage() [6/8]

void vpImageSimulator::getImage ( vpImage< vpRGBa > & I,
const vpCameraParameters & cam,
vpMatrix & zBuffer )

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 $

Definition at line 487 of file vpImageSimulator.cpp.

References vpRGBa::B, COLORED, vpPixelMeterConversion::convertPoint(), vpRGBa::G, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), GRAY_SCALED, vpMatrixException::incorrectMatrixSizeError, vpRGBa::R, and vpImagePoint::set_ij().

◆ getImage() [7/8]

void vpImageSimulator::getImage ( vpImage< vpRGBa > & I,
std::list< vpImageSimulator > & list,
const vpCameraParameters & cam )
static

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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
vpImage<vpRGBa> Icamera(480, 640, vpRGBa(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
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;
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;
sim2.init(Iimage, X);
std::list<vpImageSimulator> listSim;
listSim.addRight(sim);
listSim.addRight(sim2);
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

Definition at line 856 of file vpImageSimulator.cpp.

References vpRGBa::B, COLORED, vpPixelMeterConversion::convertPoint(), vpRGBa::G, vpRect::getBottom(), vpRect::getLeft(), vpRect::getRight(), vpRect::getTop(), GRAY_SCALED, vpRGBa::R, vpImagePoint::set_ij(), and vpImageSimulator().

◆ getImage() [8/8]

void vpImageSimulator::getImage ( vpImage< vpRGBa > & I,
vpImage< vpRGBa > & Isrc,
const vpCameraParameters & cam )

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.

Definition at line 432 of file vpImageSimulator.cpp.

References vpPixelMeterConversion::convertPoint(), and vpImagePoint::set_ij().

◆ init() [1/6]

void vpImageSimulator::init ( const char * file_image,
const std::vector< vpPoint > & X_ )

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.

Exceptions
vpException::dimensionErrorif the X_ vector is not of size 4.
  • $ 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.
X_: Vector of the 3D coordinates in the object frame (oX, oY, oZ) corresponding to the image corners.

Definition at line 1205 of file vpImageSimulator.cpp.

References vpException::dimensionError, vpImageIo::read(), and vpColVector::resize().

◆ init() [2/6]

void vpImageSimulator::init ( const char * file_image,
vpColVector * X_ )

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.

The table must have a size of 4!

  • $ 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.
X_: table of the 3D coordinates corresponding to the image corners.

Definition at line 1115 of file vpImageSimulator.cpp.

References vpImageIo::read().

◆ init() [3/6]

void vpImageSimulator::init ( const vpImage< unsigned char > & I,
const std::vector< vpPoint > & X_ )

Initialise the image thanks to an image $ I $ and a table of vector containing the 3D coordinates of the image's corners.

Exceptions
vpException::dimensionErrorif the _X vector is not of size 4.
  • $ 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.
X_: Vector of the 3D coordinates in the object frame (oX, oY, oZ) corresponding to the image corners.

Definition at line 1138 of file vpImageSimulator.cpp.

References vpImageConvert::convert(), vpException::dimensionError, and vpColVector::resize().

◆ init() [4/6]

void vpImageSimulator::init ( const vpImage< unsigned char > & I,
vpColVector * X_ )

Initialise the image thanks to an image $ I $ and a table of vector containing the 3D coordinates of the image's corners.

The table must have a size of 4!

  • $ 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.
X_: table of the 3D coordinates corresponding to the image corners.
Examples
photometricMappingVisualServoing.cpp, photometricVisualServoing.cpp, photometricVisualServoingWithoutVpServo.cpp, servoMomentImage.cpp, servoSimu4Points.cpp, tutorial-ibvs-4pts-image-tracking.cpp, and tutorial-image-simulator.cpp.

Definition at line 1071 of file vpImageSimulator.cpp.

References vpImageConvert::convert().

◆ init() [5/6]

void vpImageSimulator::init ( const vpImage< vpRGBa > & I,
const std::vector< vpPoint > & X_ )

Initialise the image thanks to an image $ I $ and a table of vector containing the 3D coordinates of the image's corners.

Exceptions
vpException::dimensionErrorif the X_ vector is not of size 4.
  • $ 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.
X_: Vector of the 3D coordinates in the object frame (oX, oY, oZ) corresponding to the image corners.

Definition at line 1170 of file vpImageSimulator.cpp.

References vpImageConvert::convert(), vpException::dimensionError, and vpColVector::resize().

◆ init() [6/6]

void vpImageSimulator::init ( const vpImage< vpRGBa > & I,
vpColVector * X_ )

Initialise the image thanks to an image $ I $ and a table of vector containing the 3D coordinates of the image's corners.

The table must have a size of 4!

  • $ 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.
X_: table of the 3D coordinates corresponding to the image corners.

Definition at line 1092 of file vpImageSimulator.cpp.

References vpImageConvert::convert().

◆ operator=()

vpImageSimulator & vpImageSimulator::operator= ( const vpImageSimulator & sim)

Definition at line 152 of file vpImageSimulator.cpp.

References setCameraPosition(), and vpImageSimulator().

◆ setBackGroundTexture()

void vpImageSimulator::setBackGroundTexture ( const vpImage< unsigned char > & Iback)
inline

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

Parameters
Iback: Image/Texture for the background

Definition at line 280 of file vpImageSimulator.h.

◆ setCameraPosition()

◆ setCleanPreviousImage()

void vpImageSimulator::setCleanPreviousImage ( const bool & clean,
const vpColor & color = vpColor::white )
inline

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.
Examples
photometricMappingVisualServoing.cpp, tutorial-ibvs-4pts-image-tracking.cpp, and tutorial-image-simulator.cpp.

Definition at line 268 of file vpImageSimulator.h.

References vpColor::white.

◆ setInterpolationType()

◆ operator<<

VISP_EXPORT std::ostream & operator<< ( std::ostream & os,
const vpImageSimulator &  )
friend

Definition at line 1548 of file vpImageSimulator.cpp.

References operator<<, and vpImageSimulator().

Referenced by operator<<.