Visual Servoing Platform  version 3.6.1 under development (2024-05-07)
tutorial-draw-frame.cpp
1 #include <visp3/gui/vpDisplayGDI.h>
3 #include <visp3/gui/vpDisplayX.h>
4 #include <visp3/core/vpHomogeneousMatrix.h>
5 
6 int main()
7 {
8  vpImage<unsigned char> I(2160, 3840, 128);
9 
10  try {
11 
12 #if defined(VISP_HAVE_X11)
14 #elif defined(VISP_HAVE_GDI)
16 #endif
17 
18  vpDisplay::setTitle(I, "My image");
20 
21  double dTheta = 45;
22  double dOffset = 0.25;
23  std::string axisName[3] = {"x", "y", "z"};
24  double px = 600; double py = 600;
25  double u0 = 320; double v0 = 240;
26 
27  // Create a camera parameter container
29 
30  // Camera initialization with a perspective projection without distortion model
31  cam.initPersProjWithoutDistortion(px,py,u0,v0);
32 
33  for(unsigned int idAxis = 0; idAxis < 3; idAxis ++)
34  {
35  unsigned int tOffset = 0;
36  for(double theta = -180; theta < 180; theta += dTheta)
37  {
38  vpTranslationVector t(0.05, 0.25 * (idAxis + 1), 0.37);
39  vpRxyzVector r(0, 0, 0);
40  t[0] = t[0] + tOffset * dOffset;
41  tOffset++;
42  r[idAxis] = vpMath::rad(theta);
44  cMo.buildFrom(t, vpRotationMatrix(r));
45  std::stringstream ss_name;
46  ss_name << "cMo_";
47  ss_name << static_cast<int>(theta);
48  ss_name << "_";
49  ss_name << axisName[idAxis];
50 
52  vpDisplay::displayFrame(I, cMo, cam, 0.1, vpColor::none, 1, vpImagePoint(), ss_name.str(), vpColor::yellow, vpImagePoint(40,40));
54  }
55  }
56 
58  std::cout << "A click to quit..." << std::endl;
60  } catch (const vpException &e) {
61  std::cout << "Catch an exception: " << e.getMessage() << std::endl;
62  }
63 }
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static const vpColor none
Definition: vpColor.h:223
static const vpColor yellow
Definition: vpColor.h:219
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:128
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
@ SCALE_AUTO
Definition: vpDisplay.h:179
error that can be emitted by ViSP classes.
Definition: vpException.h:59
const char * getMessage() const
Definition: vpException.cpp:64
Implementation of an homogeneous matrix and operations on such kind of matrices.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
static double rad(double deg)
Definition: vpMath.h:127
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:176
Class that consider the case of a translation vector.