-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_gazebo.cpp
68 lines (55 loc) · 1.75 KB
/
main_gazebo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "tracker-arb/TrackerARB.h"
namespace cv
static const std::string OPENCV_WINDOW = "Image window";
class ImageConverter {
ros::NodeHandle nh_;
image_transport::ImageTransport it_;
image_transport::Subscriber image_sub_;
image_transport::Publisher image_pub_;
public:
ImageConverter()
: it_(nh_) {
// Subscribe to input video feed and publish output video feed
image_sub_ = it_.subscribe("/iris/usb_cam/image_raw", 1,
&ImageConverter::imageCb, this);
image_pub_ = it_.advertise("/image_converter/output_video", 1);
cv::namedWindow(OPENCV_WINDOW);
}
~ImageConverter() {
cv::destroyWindow(OPENCV_WINDOW);
}
void imageCb(const sensor_msgs::ImageConstPtr &msg) {
cv_bridge::CvImagePtr cv_ptr;
try {
cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::RGB8);
}
catch (cv_bridge::Exception &e) {
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
// Update GUI Window
cv::imshow(OPENCV_WINDOW, cv_ptr->image);
cv::waitKey(3);
// Get Pose Estimate
const auto arucoSquareDimension = 3.70f;
Vec3d tVec, rVec;
CVCalibration cvl("CalibParams.txt");
TrackerARB tracker(cvl, arucoSquareDimension);
tracker.getPose(cv_ptr->image, tVec, rVec);
return 0;
// Output modified video stream
image_pub_.publish(cv_ptr->toImageMsg());
}
};
int main(int argc, char **argv) {
ros::init(argc, argv, "image_converter");
ImageConverter ic;
ros::spin();
return 0;
}