Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <cstdio>
00045
00046 #include <ros/ros.h>
00047 #include <opencv/cv.h>
00048 #include <opencv/highgui.h>
00049 #include "cv_bridge/cv_bridge.h"
00050 #include "sensor_msgs/Image.h"
00051 #include "sensor_msgs/CameraInfo.h"
00052 #include "image_transport/image_transport.h"
00053 #include <image_geometry/pinhole_camera_model.h>
00054
00055 #define GL_GLEXT_PROTOTYPES
00056 #include <GL/gl.h>
00057 #include <GL/glext.h>
00058 #include <GL/freeglut.h>
00059
00060 #include "camera_self_filter/robotMeshModel.h"
00061 #include "camera_self_filter/mask.h"
00062
00063
00064 RobotMeshModel* robmod=NULL;
00065 IplImage* ipl_maskBGRA = NULL;
00066 IplImage* ipl_maskBW = NULL;
00067
00068 bool inverted;
00069
00070 void initializeGL ()
00071 {
00072 glClearColor(0, 0, 0, 0);
00073
00074
00075 glEnable(GL_NORMALIZE);
00076 glEnable(GL_COLOR_MATERIAL);
00077 glEnable(GL_CULL_FACE);
00078 glEnable(GL_DEPTH_TEST);
00079 glShadeModel(GL_SMOOTH);
00080 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00081 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
00082 GL_LINEAR_MIPMAP_LINEAR);
00083 }
00084
00085
00086
00087
00088 void display() {
00089
00090 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00091
00092 robmod->setCamera();
00093 robmod->setCameraPose();
00094 robmod->paintRobot();
00095 glReadPixels(0, 0, robmod->cam_info_->width, robmod->cam_info_->height , GL_BGRA, GL_UNSIGNED_BYTE, ipl_maskBGRA->imageData);
00096
00097 glutSwapBuffers();
00098 }
00099
00100
00101
00102 sensor_msgs::ImagePtr calc_and_publish_BWMask(const ros::Time time_stamp, const std::string frame_id ){
00103 robmod->updateRobotLinks(time_stamp);
00104 glutPostRedisplay();
00105 glutMainLoopEvent();
00106 cvCvtColor(ipl_maskBGRA, ipl_maskBW, CV_BGRA2GRAY);
00107 cvFlip(ipl_maskBW);
00108 if (inverted)
00109 cvNot(ipl_maskBW,ipl_maskBW);
00110
00111 std_msgs::Header header;
00112 header.frame_id = frame_id;
00113 header.stamp = time_stamp;
00114 cv_bridge::CvImage cv_image(header,"mono8",ipl_maskBW);
00115 return cv_image.toImageMsg();
00116 }
00117
00118 bool calcMaskCB(camera_self_filter::maskRequest& req, camera_self_filter::maskResponse& res){
00119 sensor_msgs::ImagePtr img = calc_and_publish_BWMask(req.header.stamp, req.header.frame_id);
00120 res.mask_image = *img;
00121 return true;
00122
00123 }
00124
00125
00126 int main(int argc, char **argv) {
00127 glutInit(&argc, argv);
00128 ros::init(argc, argv, "robot_self_filter");
00129
00130
00131
00132 ros::NodeHandle nh;
00133 ros::NodeHandle nh_priv("~");
00134
00135
00136
00137
00138 std::string camera_topic;
00139 std::string camera_info_topic;
00140
00141 nh_priv.param("inverted",inverted, false);
00142 nh_priv.param<std::string>("camera_topic", camera_topic, "/wide_stereo/right/image_rect_color" );
00143 nh_priv.param<std::string>("camera_info_topic", camera_info_topic, "/wide_stereo/right/camera_info" );
00144
00145 ROS_INFO("camera topic %s", camera_topic.c_str());
00146 ROS_INFO("camera info %s", camera_info_topic.c_str());
00147
00148
00149 robmod = new RobotMeshModel;
00150
00151
00152 glutInitWindowSize (robmod->cam_info_->width, robmod->cam_info_->height);
00153 glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
00154
00155
00156 glutCreateWindow ("dummy");
00157 glutHideWindow();
00158
00159 initializeGL();
00160
00161 glutDisplayFunc (display);
00162
00163 ipl_maskBGRA = cvCreateImage(cvSize( robmod->cam_info_->width, robmod->cam_info_->height), IPL_DEPTH_8U, 4);
00164 ipl_maskBW = cvCreateImage(cvSize( robmod->cam_info_->width, robmod->cam_info_->height), IPL_DEPTH_8U, 1);
00165
00166
00167
00168
00169
00170 ros::ServiceServer mask_service = nh.advertiseService("self_mask", calcMaskCB );
00171
00172
00173 ros::spin();
00174
00175
00176
00177 cvReleaseImage(&ipl_maskBGRA);
00178 cvReleaseImage(&ipl_maskBW);
00179 delete robmod;
00180 return 0;
00181 }
00182