cpp 初心者です。
cpp のclassについて質問なのですが、
このソースコードのclass内の
・14〜20行までの部分
・21行目の部分
は何を表していて、どういう使い方ができるんでしょうか?
SavePCDのクラスをインスタンス化する時にどういった使い方ができるかよくわかないので、教えて下さい。よろしくお願いします。
該当部分
c++
1SavePCD() : save_count(0) { 2 //* subscribe ROS topics 3 _sub1 = _nh.subscribe ("/camera/rgb/image_color", 1, &SavePCD::image_cb, this); 4 ROS_INFO ("Listening for incoming data on topic /camera/rgb/image_color ..." ); 5 _sub2 = _nh.subscribe ("/camera/depth_registered/points", 1, &SavePCD::points_cb, this); 6 ROS_INFO ("Listening for incoming data on topic /camera/depth_registered/points ..." ); 7 } 8 ~SavePCD() {}
ソースコード
https://github.com/kanezaki/ssii2016_tutorial/blob/master/save_pcd.cpp
ソースコード
c++
1 2#include <ros/ros.h> 3#include <cv_bridge/cv_bridge.h> 4#include <opencv2/highgui/highgui.hpp> 5#include <pcl_ros/io/pcd_io.h> 6#include <sensor_msgs/image_encodings.h> 7 8class SavePCD { 9private: 10 ros::NodeHandle _nh; 11 ros::Subscriber _sub1, _sub2; 12 pcl::PointCloud<pcl::PointXYZRGB> input_cloud; 13 int save_count; 14public: 15 SavePCD() : save_count(0) { 16 //* subscribe ROS topics 17 _sub1 = _nh.subscribe ("/camera/rgb/image_color", 1, &SavePCD::image_cb, this); 18 ROS_INFO ("Listening for incoming data on topic /camera/rgb/image_color ..." ); 19 _sub2 = _nh.subscribe ("/camera/depth_registered/points", 1, &SavePCD::points_cb, this); 20 ROS_INFO ("Listening for incoming data on topic /camera/depth_registered/points ..." ); 21 } 22 ~SavePCD() {} 23 24 //* get points 25 void points_cb( const sensor_msgs::PointCloud2ConstPtr& cloud ){ 26 if ((cloud->width * cloud->height) == 0) 27 return; 28 pcl::fromROSMsg (*cloud, input_cloud); 29 } 30 31 //* show color img and save color img + point cloud 32 void image_cb( const sensor_msgs::ImageConstPtr& msg ){ 33 cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(msg); 34 35 //* show color img 36 cv::Mat color_img = cv_ptr->image; 37 cv::imshow( "color image", color_img ); 38 cv::waitKey(10); 39 40 if ((input_cloud.width * input_cloud.height) == 0) 41 return; 42 43 //* save 44 std::stringstream filename1; 45 filename1 << save_count << ".png"; 46 cv::imwrite( filename1.str(), color_img ); 47 std::cout << filename1.str() << " saved." << std::endl; 48 std::stringstream filename2; 49 filename2 << save_count << ".pcd"; 50 pcl::io::savePCDFileBinary( filename2.str(), input_cloud ); 51 std::cout << filename2.str() << " saved." << std::endl; 52 save_count++; 53 usleep( 300000 ); 54 } 55}; 56 57int main( int argc, char** argv ){ 58 ros::init(argc,argv,"save_pcd"); 59 SavePCD spcd; 60 ros::spin(); 61 62 return 1; 63}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。