Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
tutorial-franka-acquire-calib-data.cpp
1 #include <iostream>
3 
4 #include <visp3/core/vpCameraParameters.h>
5 #include <visp3/core/vpXmlParserCamera.h>
6 #include <visp3/gui/vpDisplayGDI.h>
7 #include <visp3/gui/vpDisplayX.h>
8 #include <visp3/io/vpImageIo.h>
9 #include <visp3/sensor/vpRealSense2.h>
10 #include <visp3/robot/vpRobotFranka.h>
11 
12 #if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_FRANKA)
13 
14 int main(int argc, char **argv)
15 {
16  try {
17  std::string robot_ip = "192.168.1.1";
18 
19  for (int i = 1; i < argc; i++) {
20  if (std::string(argv[i]) == "--ip" && i + 1 < argc) {
21  robot_ip = std::string(argv[i + 1]);
22  }
23  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
24  std::cout << argv[0] << " [--ip 192.168.1.1] [--help] [-h]"
25  << "\n";
26  return EXIT_SUCCESS;
27  }
28  }
29 
31 
32  vpRobotFranka robot;
33  robot.connect(robot_ip);
34 
35  vpRealSense2 g;
36  rs2::config config;
37  config.disable_stream(RS2_STREAM_DEPTH);
38  config.disable_stream(RS2_STREAM_INFRARED);
39  config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30);
40  g.open(config);
41  g.acquire(I);
42 
43  unsigned int width = I.getWidth();
44  unsigned int height = I.getHeight();
45 
46  std::cout << "Image size: " << width << " x " << height << std::endl;
47  // Save intrinsics
49  vpXmlParserCamera xml_camera;
51  xml_camera.save(cam, "camera.xml", "Camera", width, height);
52 
53 #if defined(VISP_HAVE_X11)
54  vpDisplayX dc(I, 10, 10, "Color image");
55 #elif defined(VISP_HAVE_GDI)
56  vpDisplayGDI dc(I, 10, 10, "Color image");
57 #endif
58 
59  bool end = false;
60  unsigned cpt = 0;
61  while (! end) {
62  g.acquire(I);
63 
65 
66  vpDisplay::displayText(I, 15, 15, "Left click to acquire data", vpColor::red);
67  vpDisplay::displayText(I, 30, 15, "Right click to quit", vpColor::red);
69  if (vpDisplay::getClick(I, button, false)) {
70  if (button == vpMouseButton::button1) {
71  cpt ++;
72 
73  vpPoseVector fPe;
75 
76  std::stringstream ss_img, ss_pos;
77 
78  ss_img << "image-" << cpt << ".png";
79  ss_pos << "pose_fPe_" << cpt << ".yaml";
80  std::cout << "Save: " << ss_img.str() << " and " << ss_pos.str() << std::endl;
81  vpImageIo::write(I, ss_img.str());
82  fPe.saveYAML(ss_pos.str(), fPe);
83  }
84  else if (button == vpMouseButton::button3) {
85  end = true;
86  }
87  }
89 
90  }
91  } catch (const vpException &e) {
92  std::cerr << "RealSense error " << e.what() << std::endl;
93  } catch (const std::exception &e) {
94  std::cerr << e.what() << std::endl;
95  }
96 
97  return 0;
98 }
99 #else
100 int main()
101 {
102 #if !defined(VISP_HAVE_REALSENSE2)
103  std::cout << "Install librealsense-2.x." << std::endl;
104 #endif
105 #if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
106  std::cout << "Build ViSP with c++11 or higher compiler flag (cmake -DUSE_CXX_STANDARD=11)." << std::endl;
107 #endif
108 #if !defined(VISP_HAVE_FRANKA)
109  std::cout << "Install libfranka." << std::endl;
110 #endif
111 
112  std::cout << "After installation of the missing 3rd parties, configure ViSP with cmake"
113  << " and build ViSP again." << std::endl;
114  return 0;
115 }
116 #endif
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:831
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
error that can be emited by ViSP classes.
Definition: vpException.h:71
void open(const rs2::config &cfg=rs2::config())
XML parser to load and save intrinsic camera parameters.
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:179
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:445
static void display(const vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
void acquire(vpImage< unsigned char > &grey)
const char * what() const
unsigned int getHeight() const
Definition: vpImage.h:186
vpCameraParameters getCameraParameters(const rs2_stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion) const
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:151
int save(const vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, unsigned int image_width=0, unsigned int image_height=0, const std::string &additionalInfo="")
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
void connect(const std::string &franka_address, franka::RealtimeConfig realtime_config=franka::RealtimeConfig::kEnforce)
unsigned int getWidth() const
Definition: vpImage.h:244