head_registration_srv.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include <hrl_head_registration/head_registration.h>
00004 #include <hrl_head_registration/HeadRegistration.h>
00005 #include <geometry_msgs/TransformStamped.h>
00006 
00007 typedef hrl_head_registration::HeadRegistration HeadRegSrv;
00008 
00009 PCRGB::Ptr cur_pc, template_pc;
00010 
00011 ros::Subscriber pc_sub;
00012 ros::ServiceServer reg_srv;
00013 ros::Publisher aligned_pub; 
00014         
00015 void subPCCallback(const PCRGB::Ptr& cur_pc_);
00016 bool regCallback(HeadRegSrv::Request& req, HeadRegSrv::Response& resp);
00017 
00018 void subPCCallback(const PCRGB::Ptr& cur_pc_)
00019 {
00020     cur_pc = cur_pc_;
00021 }
00022 
00023 void readTFBag(const string& filename, geometry_msgs::TransformStamped::Ptr& tf_msg) 
00024 {
00025     rosbag::Bag bag;
00026     bag.open(filename, rosbag::bagmode::Read);
00027     rosbag::View view(bag, rosbag::TopicQuery("/itf_transform"));
00028     BOOST_FOREACH(rosbag::MessageInstance const msg, view) {
00029         tf_msg = msg.instantiate< geometry_msgs::TransformStamped >();
00030         break;
00031     }
00032     bag.close();
00033 }
00034 
00035 bool regCallback(HeadRegSrv::Request& req, HeadRegSrv::Response& resp)
00036 {
00037     if(!cur_pc) {
00038         ROS_ERROR("[head_registraion] No point cloud received.");
00039         return false;
00040     }
00041     Eigen::Affine3d tf_mat;
00042     if(!findFaceRegistration(template_pc, cur_pc, req.u, req.v, tf_mat)) {
00043         ROS_ERROR("[head_registraion] Bad initialization pixel.");
00044         return false;
00045     }
00046     resp.tf_reg.header.frame_id = cur_pc->header.frame_id;
00047     resp.tf_reg.header.stamp = ros::Time::now();
00048     tf::poseEigenToMsg(tf_mat, resp.tf_reg.pose);
00049 
00050     // TODO SHAVING_SIDE
00051     string shaving_side;
00052     ros::param::param<string>("/shaving_side", shaving_side, "r");
00053     double new_hue = (shaving_side[0] == 'r') ? 120 : 240;
00054     // TODO END SHAVING_SIDE
00055 
00056     PCRGB::Ptr aligned_pc(new PCRGB());
00057     transformPC(*template_pc, *aligned_pc, tf_mat.inverse());
00058     double h, s, l;
00059     for(uint32_t i=0;i<aligned_pc->size();i++) {
00060         extractHSL(aligned_pc->points[i].rgb, h, s, l);
00061         writeHSL(new_hue, 50, l, aligned_pc->points[i].rgb);
00062     }
00063     aligned_pc->header.frame_id = cur_pc->header.frame_id;
00064     aligned_pub.publish(aligned_pc);
00065 
00066 #if 0
00067     vector<PCRGB::Ptr> pcs;
00068     vector<string> pc_topics;
00069 
00070     PCRGB::Ptr skin_pc(new PCRGB());
00071     extractFaceColorModel(cur_pc, skin_pc, req.u, req.v);
00072     skin_pc->header.frame_id = "/openni_rgb_optical_frame";
00073     pcs.push_back(skin_pc);
00074     pc_topics.push_back("/target_pc");
00075 
00076     PCRGB::Ptr tf_pc(new PCRGB());
00077     transformPC(*template_pc, *tf_pc, tf_mat);
00078     tf_pc->header.frame_id = "/openni_rgb_optical_frame";
00079     pcs.push_back(tf_pc);
00080     pc_topics.push_back("/template_pc");
00081 
00082     pubLoop(pcs, pc_topics, 5);
00083 #endif
00084     return true;
00085 }
00086 
00087 int main(int argc, char **argv)
00088 {
00089     ros::init(argc, argv, "head_registration");
00090     ros::NodeHandle nh;
00091 
00092     readPCBag(argv[1], template_pc);
00093 
00094     aligned_pub = nh.advertise<PCRGB>("/head_registration/aligned_pc", 1, true);
00095     pc_sub = nh.subscribe("/points", 1, &subPCCallback);
00096     reg_srv = nh.advertiseService("/head_registration", &regCallback);
00097     ros::spin();
00098 
00099     return 0;
00100 }


hrl_head_registration
Author(s): Kelsey Hawkins
autogenerated on Wed Nov 27 2013 11:45:27