19 #include "asr_recognizer_prediction_psm/recognizer_prediction_psm.h" 20 #include <sensor_msgs/PointCloud2.h> 21 #include <asr_msgs/AsrAttributedPointCloud.h> 22 #include <asr_msgs/AsrObject.h> 43 bool generate_hyps(asr_recognizer_prediction_psm::recognizer_prediction_psm::Request &req,
44 asr_recognizer_prediction_psm::recognizer_prediction_psm::Response &res)
47 bool visualize_hypothesis =
true;
49 if(!n.
getParam(
"/recognizer_prediction_psm/visualize_hypothesis", visualize_hypothesis))
50 visualize_hypothesis =
true;
53 std::string path = req.pathToXML;
54 std::vector<std::string> scene_list = req.scenes;
55 std::vector<float> scene_probabilities = req.scene_probabilities;
56 std::vector<int> votes_per_scene;
57 uint32_t num_votes = req.num_votes;
58 std::vector<asr_msgs::AsrObject> objects = req.objects;
59 std::vector<boost::shared_ptr<asr_msgs::AsrObject>> object_pointers;
63 if(scene_list.size() != scene_probabilities.size())
65 ROS_ERROR(
"The number of scenes has to be equal to the number of scene probabilities!");
69 if(objects.size() < 1)
71 ROS_ERROR(
"There has to be at least one observed object!");
75 ROS_INFO(
"Overall number of hypothesis that should be generated: %i", num_votes);
77 for(
unsigned int i=0;i<scene_list.size();i++)
79 votes_per_scene.push_back((
int) (scene_probabilities.at(i) * num_votes));
81 ROS_INFO(
"Loaded scene %s with probability %.2f. Number of hypothesis for this scene %i",
82 scene_list.at(i).c_str(),
83 scene_probabilities.at(i),
84 votes_per_scene.at(i));
88 for(asr_msgs::AsrObject o : objects)
91 if(!o.sampledPoses.size()){
92 std::cerr <<
"Got a AsrObject without poses." << std::endl;
98 p->identifier = o.identifier;
99 p->header.frame_id = o.header.frame_id;
100 p->sampledPoses.push_back(o.sampledPoses.at(0));
101 object_pointers.push_back(p);
112 std::vector<ASR::AttributedPoint> pose_hypotheses;
113 std::vector<ASR::AttributedPoint> found_objects;
114 bool all_scene_objects_found =
true;
118 for(
unsigned int i=0;i<scene_list.size();i++)
120 ROS_INFO(
"\nPath: %s\nCurrent Scene: %s\n", path.c_str(), scene_list.at(i).c_str());
129 votes_per_scene.at(i),
136 engine->calcHypotheses();
142 engine->collectPoseHypothesesRecursive(pose_hypotheses, found_objects);
149 if(engine->getNumberOfMissingObjects() > 0 && scene_list.at(i).compare(
"background") != 0)
150 all_scene_objects_found =
false;
161 asr_msgs::AsrAttributedPointCloud msg;
163 for(
unsigned int i=0; i<pose_hypotheses.size();i++)
165 asr_msgs::AsrAttributedPoint element;
167 element.type = pose_hypotheses.at(i).objectType;
168 element.pose = pose_hypotheses.at(i).pose;
170 msg.elements.push_back(element);
172 res.pose_hypothesis = msg;
173 res.all_scene_objects_found = all_scene_objects_found;
181 if(visualize_hypothesis)
184 vis->generateMarkerArray(pose_hypotheses, found_objects );
187 for(
int i=0;i<5;i++) {
189 vis->publishMarkerArray();
197 int main(
int argc,
char **argv)
199 ros::init(argc, argv,
"generate_hypothesis_server");
203 ROS_INFO(
"Ready to generate hypothesis\n");
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ROSCPP_DECL void spin(Spinner &spinner)
bool generate_hyps(asr_recognizer_prediction_psm::recognizer_prediction_psm::Request &req, asr_recognizer_prediction_psm::recognizer_prediction_psm::Response &res)
generate_hyps
int main(int argc, char **argv)
bool getParam(const std::string &key, std::string &s) const