StereoNode.cc
Go to the documentation of this file.
1 #include "StereoNode.h"
2 
6 
7 int main(int argc, char **argv)
8 {
9  ros::init(argc, argv, "Stereo");
10  ros::start();
11 
12  if(argc > 1) {
13  ROS_WARN ("Arguments supplied via command line are neglected.");
14  }
15 
16  ros::NodeHandle node_handle;
18 
19  // initialize
20  StereoNode node (ORB_SLAM2::System::STEREO, node_handle, image_transport);
21 
22  node.Init();
23 
24  ros::spin();
25 
26  return 0;
27 }
28 
29 
30 StereoNode::StereoNode (const ORB_SLAM2::System::eSensor sensor, ros::NodeHandle &node_handle, image_transport::ImageTransport &image_transport) : Node (sensor, node_handle, image_transport) {
31  left_sub_ = new message_filters::Subscriber<sensor_msgs::Image> (node_handle, "image_left/image_color_rect", 1);
32  right_sub_ = new message_filters::Subscriber<sensor_msgs::Image> (node_handle, "image_right/image_color_rect", 1);
33  camera_info_topic_ = "image_left/camera_info";
34 
36  sync_->registerCallback(boost::bind(&StereoNode::ImageCallback, this, _1, _2));
37 }
38 
39 
41  delete left_sub_;
42  delete right_sub_;
43  delete sync_;
44 }
45 
46 
47 void StereoNode::ImageCallback (const sensor_msgs::ImageConstPtr& msgLeft, const sensor_msgs::ImageConstPtr& msgRight) {
48  cv_bridge::CvImageConstPtr cv_ptrLeft;
49  try {
50  cv_ptrLeft = cv_bridge::toCvShare(msgLeft);
51  } catch (cv_bridge::Exception& e) {
52  ROS_ERROR("cv_bridge exception: %s", e.what());
53  return;
54  }
55 
56  cv_bridge::CvImageConstPtr cv_ptrRight;
57  try {
58  cv_ptrRight = cv_bridge::toCvShare(msgRight);
59  } catch (cv_bridge::Exception& e) {
60  ROS_ERROR("cv_bridge exception: %s", e.what());
61  return;
62  }
63 
64  current_frame_time_ = msgLeft->header.stamp;
65 
66  orb_slam_->TrackStereo(cv_ptrLeft->image, cv_ptrRight->image, cv_ptrLeft->header.stamp.toSec());
67 
68  Update ();
69 }
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
std::string camera_info_topic_
Definition: Node.h:66
message_filters::Synchronizer< sync_pol > * sync_
Definition: StereoNode.h:35
ROSCPP_DECL void start()
Definition: Node.h:54
void ImageCallback(const sensor_msgs::ImageConstPtr &msgLeft, const sensor_msgs::ImageConstPtr &msgRight)
Definition: StereoNode.cc:47
message_filters::Subscriber< sensor_msgs::Image > * right_sub_
Definition: StereoNode.h:34
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ORB_SLAM2::System * orb_slam_
Definition: Node.h:63
void TrackStereo(const cv::Mat &imLeft, const cv::Mat &imRight, const double &timestamp)
Definition: System.cc:125
#define ROS_WARN(...)
ROSCPP_DECL void spin(Spinner &spinner)
ros::Time current_frame_time_
Definition: Node.h:64
void Init()
Definition: Node.cc:23
int main(int argc, char **argv)
Definition: StereoNode.cc:7
message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image > sync_pol
Definition: StereoNode.h:32
message_filters::Subscriber< sensor_msgs::Image > * left_sub_
Definition: StereoNode.h:33
void Update()
Definition: Node.cc:66
#define ROS_ERROR(...)
StereoNode(const ORB_SLAM2::System::eSensor sensor, ros::NodeHandle &node_handle, image_transport::ImageTransport &image_transport)
Definition: StereoNode.cc:30


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05