Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <cv_bridge/cv_bridge.h>
00018 #include <image_geometry/pinhole_camera_model.h>
00019 #include <iostream>
00020 #include <ros/ros.h>
00021 #include <sensor_msgs/CameraInfo.h>
00022 #include <visualization_msgs/Marker.h>
00023
00024 class FOVNode
00025 {
00026 public:
00030 FOVNode ()
00031 {
00032 pub_marker_ = n_.advertise<visualization_msgs::Marker>("cam_fov",10);
00033 sub_cam_ = n_.subscribe("camera_info", 10, &FOVNode::camCallback, this);
00034 }
00035
00037 ~FOVNode ()
00038 {
00040 }
00041
00042 private:
00043 ros::NodeHandle n_;
00044
00045 ros::Publisher pub_marker_;
00046 ros::Subscriber sub_cam_;
00047 void camCallback(const sensor_msgs::CameraInfo::ConstPtr& msg);
00048 };
00049
00050 void FOVNode::camCallback(const sensor_msgs::CameraInfo::ConstPtr& msg)
00051 {
00052 bool show_marker;
00053 double min_distance, max_distance;
00054 ros::param::get("~show_marker", show_marker);
00055 ros::param::get("~min_distance", min_distance);
00056 ros::param::get("~max_distance", max_distance);
00057
00058 if(show_marker==true)
00059 {
00060 sensor_msgs::CameraInfo camerainfo = *msg;
00061 image_geometry::PinholeCameraModel pinmodel;
00062 pinmodel.fromCameraInfo(camerainfo);
00063
00064 visualization_msgs::Marker cam_poly;
00065 cam_poly.header = camerainfo.header;
00066 cam_poly.action = visualization_msgs::Marker::ADD;
00067 cam_poly.id = 0;
00068 cam_poly.ns = "fov";
00069 cam_poly.type = visualization_msgs::Marker::LINE_STRIP;
00070 cam_poly.scale.x = 0.01;
00071 cam_poly.color.g = 1.0;
00072 cam_poly.color.b = 1.0;
00073 cam_poly.color.a = 0.5;
00074
00075
00076 cv::Point3d P_topleft = pinmodel.projectPixelTo3dRay(cv::Point(0, 0));
00077 cv::Point3d P_downright = pinmodel.projectPixelTo3dRay(cv::Point(camerainfo.width, camerainfo.height));
00078 cv::Point3d P_topright = pinmodel.projectPixelTo3dRay(cv::Point(camerainfo.width, 0));
00079 cv::Point3d P_downleft = pinmodel.projectPixelTo3dRay(cv::Point(0, camerainfo.height));
00080
00081
00082
00083
00084
00085 geometry_msgs::Point p1, p2, p3, p4, p5, p6, p7, p8;
00086 p1.x = P_topleft.x * min_distance;
00087 p1.y = P_topleft.y * min_distance;
00088 p1.z = P_topleft.z * min_distance;
00089
00090 p2.x = P_topright.x * min_distance;
00091 p2.y = P_topright.y * min_distance;
00092 p2.z = P_topright.z * min_distance;
00093
00094 p3.x = P_downright.x * min_distance;
00095 p3.y = P_downright.y * min_distance;
00096 p3.z = P_downright.z * min_distance;
00097
00098 p4.x = P_downleft.x * min_distance;
00099 p4.y = P_downleft.y * min_distance;
00100 p4.z = P_downleft.z * min_distance;
00101
00102
00103 p5.x = P_topleft.x * max_distance;
00104 p5.y = P_topleft.y * max_distance;
00105 p5.z = P_topleft.z * max_distance;
00106
00107 p6.x = P_topright.x * max_distance;
00108 p6.y = P_topright.y * max_distance;
00109 p6.z = P_topright.z * max_distance;
00110
00111 p7.x= P_downright.x * max_distance;
00112 p7.y= P_downright.y * max_distance;
00113 p7.z= P_downright.z * max_distance;
00114
00115 p8.x= P_downleft.x * max_distance;
00116 p8.y= P_downleft.y * max_distance;
00117 p8.z= P_downleft.z * max_distance;
00118
00119
00120 cam_poly.points.push_back(p1);
00121 cam_poly.points.push_back(p2);
00122 cam_poly.points.push_back(p3);
00123 cam_poly.points.push_back(p4);
00124 cam_poly.points.push_back(p1);
00125 cam_poly.points.push_back(p5);
00126 cam_poly.points.push_back(p6);
00127 cam_poly.points.push_back(p7);
00128 cam_poly.points.push_back(p8);
00129 cam_poly.points.push_back(p5);
00130 cam_poly.points.push_back(p8);
00131 cam_poly.points.push_back(p4);
00132 cam_poly.points.push_back(p3);
00133 cam_poly.points.push_back(p7);
00134 cam_poly.points.push_back(p6);
00135 cam_poly.points.push_back(p2);
00136
00137 pub_marker_.publish(cam_poly);
00138
00139
00140 }
00141 }
00142
00143 int main(int argc, char *argv[])
00144 {
00145 ros::init(argc, argv, "visualize_cam_fov");
00146 FOVNode fov;
00147 ros::spin();
00148 return 0;
00149 }