21 #include <sensor_msgs/CameraInfo.h> 22 #include <visualization_msgs/Marker.h> 47 void camCallback(
const sensor_msgs::CameraInfo::ConstPtr& msg);
53 double min_distance, max_distance;
60 sensor_msgs::CameraInfo camerainfo = *msg;
64 visualization_msgs::Marker cam_poly;
65 cam_poly.header = camerainfo.header;
66 cam_poly.action = visualization_msgs::Marker::ADD;
69 cam_poly.type = visualization_msgs::Marker::LINE_STRIP;
70 cam_poly.scale.x = 0.01;
71 cam_poly.color.g = 1.0;
72 cam_poly.color.b = 1.0;
73 cam_poly.color.a = 0.5;
77 cv::Point3d P_downright = pinmodel.
projectPixelTo3dRay(cv::Point(camerainfo.width, camerainfo.height));
85 geometry_msgs::Point p1, p2, p3, p4, p5, p6, p7, p8;
86 p1.x = P_topleft.x * min_distance;
87 p1.y = P_topleft.y * min_distance;
88 p1.z = P_topleft.z * min_distance;
90 p2.x = P_topright.x * min_distance;
91 p2.y = P_topright.y * min_distance;
92 p2.z = P_topright.z * min_distance;
94 p3.x = P_downright.x * min_distance;
95 p3.y = P_downright.y * min_distance;
96 p3.z = P_downright.z * min_distance;
98 p4.x = P_downleft.x * min_distance;
99 p4.y = P_downleft.y * min_distance;
100 p4.z = P_downleft.z * min_distance;
103 p5.x = P_topleft.x * max_distance;
104 p5.y = P_topleft.y * max_distance;
105 p5.z = P_topleft.z * max_distance;
107 p6.x = P_topright.x * max_distance;
108 p6.y = P_topright.y * max_distance;
109 p6.z = P_topright.z * max_distance;
111 p7.x= P_downright.x * max_distance;
112 p7.y= P_downright.y * max_distance;
113 p7.z= P_downright.z * max_distance;
115 p8.x= P_downleft.x * max_distance;
116 p8.y= P_downleft.y * max_distance;
117 p8.z= P_downleft.z * max_distance;
120 cam_poly.points.push_back(p1);
121 cam_poly.points.push_back(p2);
122 cam_poly.points.push_back(p3);
123 cam_poly.points.push_back(p4);
124 cam_poly.points.push_back(p1);
125 cam_poly.points.push_back(p5);
126 cam_poly.points.push_back(p6);
127 cam_poly.points.push_back(p7);
128 cam_poly.points.push_back(p8);
129 cam_poly.points.push_back(p5);
130 cam_poly.points.push_back(p8);
131 cam_poly.points.push_back(p4);
132 cam_poly.points.push_back(p3);
133 cam_poly.points.push_back(p7);
134 cam_poly.points.push_back(p6);
135 cam_poly.points.push_back(p2);
143 int main(
int argc,
char *argv[])
145 ros::init(argc, argv,
"visualize_cam_fov");
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
cv::Point3d projectPixelTo3dRay(const cv::Point2d &uv_rect) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher pub_marker_
ros::NodeHandle n_
ROS node handle.
ROSCPP_DECL bool get(const std::string &key, std::string &s)
bool fromCameraInfo(const sensor_msgs::CameraInfo &msg)
void camCallback(const sensor_msgs::CameraInfo::ConstPtr &msg)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char *argv[])