ed_sensor_integration
fitter_viz_live.cpp
Go to the documentation of this file.
1 #include <ed/entity.h>
2 #include <ed/world_model.h>
3 
4 #include <ed/kinect/fitter.h>
5 
6 #include <geolib/math_types.h>
7 
9 
10 #include <opencv2/highgui/highgui.hpp>
11 
14 
15 
19 void usage()
20 {
21  std::cout << "Usage: ed_fitter_live WORLDMODEL_NAME ENTITY_ID RGBD_TOPIC" << std::endl
22  << "WORLDMODEL_NAME name of the worldmodel to load, example: impuls" << std::endl
23  << "ENTITY_ID entity to fit, example dinner_table" << std::endl
24  << "RGBD_TOPIC topic on which the rgbd image is published, example /hero/head_rgbd_sensor/rgbd" << std::endl;
25 }
26 
32 int main(int argc, char **argv)
33 {
34  // input processed. starting implementation
35  ros::init(argc, argv, "fitting_visualizer");
36 
37  if (argc != 4)
38  {
39  usage();
40  return 1;
41  }
42 
43  std::string model_name = argv[1];
44 
45  ed::WorldModelPtr world_model;
46  try
47  {
48  world_model = ed::loadWorldModel(model_name);
49  }
50  catch (const ed::ModelNotFoundException& e)
51  {
52  std::cerr << "World model '" << model_name << "' could not be loaded." << std::endl;
53  std::cerr << e.what() << std::endl;
54  return 1;
55  }
56 
57  std::string entity_id = argv[2];
58  ed::EntityConstPtr e = world_model->getEntity(entity_id);
59  if (!e)
60  {
61  std::cerr << "Entity '" << entity_id << "' could not be found in world model '" << model_name << "'." << std::endl;
62  return 1;
63  }
64 
65  std::string topic = argv[3];
66  std::cout << "Using topic: " << topic << std::endl;
67 
68  rgbd::ImageBuffer image_buffer;
69  image_buffer.initialize(topic, "map");
70 
71  Fitter fitter;
72 
73  while(ros::ok())
74  {
76  geo::Pose3D sensor_pose;
77 
78  if (!image_buffer.waitForRecentImage(image, sensor_pose, 2.0))
79  {
80  std::cerr << "No image received, will try again." << std::endl;
81  continue;
82  }
83 
84  FitterData fitterdata;
85  geo::Pose3D fitted_pose;
86 
87  fitter.configureBeamModel(image->getCameraModel());
88  fitter.processSensorData(*image, sensor_pose, fitterdata);
89 
90  bool estimateEntityPose = fitter.estimateEntityPose(fitterdata, *world_model, entity_id, e->pose(), fitted_pose);
91 
92  // poses for visualization
93  geo::Transform2 sensor_pose2d = fitterdata.sensor_pose_xya.projectTo2d();
94  geo::Transform2 entity_pose2d = e->pose().projectTo2d();
95  geo::Transform2 fitted_pose2d = fitted_pose.projectTo2d();
96 
97  // show snapshot
98  cv::Mat rgbcanvas = image->getRGBImage();
99  cv::imshow("RGB", rgbcanvas);
100 
101  EntityRepresentation2D entity_2d = fitter.GetOrCreateEntity2D(e);
102  cv::Mat canvas = visualizeFitting(entity_2d, sensor_pose2d, entity_pose2d, fitted_pose2d, fitterdata, estimateEntityPose);
103  cv::imshow("Fitting", canvas);
104 
105  char key = cv::waitKey(30);
106 
107  if (key == 82) // Up arrow
108  {
110  }
111  else if (key == 84) // Down arrow
112  {
114  }
115  else if (key == 'q')
116  {
117  break;
118  }
119  }
120  cv::destroyAllWindows();
121  return 0;
122 }
std::string
std::shared_ptr
fitter_viz.h
FitterData::sensor_pose_xya
geo::Pose3D sensor_pose_xya
Definition: fitter.h:73
std::cerr
geo::Transform3T
Fitter::estimateEntityPose
bool estimateEntityPose(const FitterData &data, const ed::WorldModel &world, const ed::UUID &id, const geo::Pose3D &expected_pose, geo::Pose3D &fitted_pose, double max_yaw_change=M_PI) const
estimateEntityPose performs the entity pose estimation. Basically, tries to call estimateEntityPoseIm...
Definition: fitter.cpp:258
ed::loadWorldModel
ed::WorldModelPtr loadWorldModel(const std::string &model_name)
Definition: snapshot.h:115
FitterData
The FitterData struct contains the downprojected (hence 2D) sensor readings as well as the sensor pos...
Definition: fitter.h:68
EntityRepresentation2D
The EntityRepresentation2D struct contains the (downprojected) shape that is used for the fitting.
Definition: fitter.h:55
rgbd::ImageBuffer
ed::EntityConstPtr
shared_ptr< const Entity > EntityConstPtr
image
cv::Mat image
std::cout
main
int main(int argc, char **argv)
main executable to visualise the fitting process of live images.
Definition: fitter_viz_live.cpp:32
Fitter::GetOrCreateEntity2D
EntityRepresentation2D GetOrCreateEntity2D(const ed::EntityConstPtr &e) const
GetOrCreateEntity2D returns the downprojected shape of the entity. If it's already in the cache,...
Definition: fitter.cpp:528
geo::Transform2T
usage
void usage()
usage, print how the executable should be used and explain the input
Definition: fitter_viz_live.cpp:19
ed::WorldModelPtr
shared_ptr< WorldModel > WorldModelPtr
visualizeFitting
cv::Mat visualizeFitting(EntityRepresentation2D entity, geo::Transform2 sensor_pose, geo::Transform2 entity_pose, geo::Transform2 fitted_pose, FitterData fitterdata, bool estimateEntityPose)
Definition: fitter_viz.h:114
geo::Transform3T::projectTo2d
Transform2T< T > projectTo2d() const
world_model.h
std::endl
T endl(T... args)
snapshot.h
rgbd::ImageBuffer::waitForRecentImage
bool waitForRecentImage(rgbd::ImageConstPtr &image, geo::Pose3D &sensor_pose, double timeout_sec, double check_rate)
fitter.h
canvas_resolution
float canvas_resolution
Definition: fitter_viz.h:17
rgbd::ImageBuffer::initialize
void initialize(const std::string &topic, const std::string &root_frame="map", const float worker_thread_frequency=20)
Fitter::configureBeamModel
void configureBeamModel(const image_geometry::PinholeCameraModel &cammodel)
configure the beam model (nr of data points and focal length) according to the camera you are using.
Definition: fitter.cpp:475
Fitter::processSensorData
void processSensorData(const rgbd::Image &image, const geo::Pose3D &sensor_pose, FitterData &data) const
processSensorData pre-processes sensor data, i.e., performs a downprojection of the input depth image...
Definition: fitter.cpp:486
std::max
T max(T... args)
Fitter
The Fitter class contains the algorithm to do the 2D fit of an entity.
Definition: fitter.h:100
math_types.h
entity.h
image_buffer.h
ed::ModelNotFoundException
Definition: snapshot.h:29
ed::ModelNotFoundException::what
const char * what() const
Definition: snapshot.h:39