Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
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) && defined(VISP_HAVE_CPP11_COMPATIBILITY) && (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 !defined(VISP_HAVE_CPP11_COMPATIBILITY)
106  std::cout << "Build ViSP with C++11 compiler flag (cmake -DUSE_CPP11=ON)." << 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:612
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
Definition: vpImage.h:239
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
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:151
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)
vpCameraParameters getCameraParameters(const rs2_stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion) const
static const vpColor red
Definition: vpColor.h:180
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:375
const char * what() const
static void display(const vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
void acquire(vpImage< unsigned char > &grey)
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:92
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
void connect(const std::string &franka_address, franka::RealtimeConfig realtime_config=franka::RealtimeConfig::kEnforce)
unsigned int getHeight() const
Definition: vpImage.h:178
int save(const vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const unsigned int image_width=0, const unsigned int image_height=0, const std::string &additionalInfo="")