26 #include <dynamic_reconfigure/server.h> 27 #include <visualization_msgs/MarkerArray.h> 29 #include <asr_msgs/AsrObject.h> 31 #include <asr_ism_visualizations/ism_result_visualizer_rviz.hpp> 32 #include <asr_ism_visualizations/ism_voting_visualizer_rviz.hpp> 33 #include <asr_ism_visualizations/ism_pose_prediction_visualizer_rviz.hpp> 34 #include <asr_ism_visualizations/ObjectModelVisualizerRVIZ.hpp> 35 #include <asr_ism_visualizations/VizHelperRVIZ.hpp> 37 #include <pose_prediction_ism/pose_predictor.h> 38 #include <pose_prediction_ism/shortest_path.h> 41 #include <ISM/recognizer/Recognizer.hpp> 42 #include <ISM/utility/TableHelper.hpp> 43 #include <ISM/utility/Util.hpp> 44 #include <ISM/common_type/Pose.hpp> 45 #include <ISM/typedef.hpp> 47 #include "ISM/rating/BaseRater.hpp" 48 #include "ISM/rating/SimpleRater.hpp" 49 #include "ISM/rating/APORater.hpp" 50 #define SIMPLE_RATER 0 54 #include <asr_ism/recognizerConfig.h> 60 #define KEYCODE_BUFFERVOTES 0x23//# 61 #define KEYCODE_VISUALIZE 0x76 //v 63 #define KEYCODE_BUFFERSCENE 0x2B //+ 64 #define KEYCODE_PREDICTSCENE 0x70 //p 65 #define KEYCODE_NEXTREF 0x79 //y 66 #define KEYCODE_PREVREF 0x3C //< 67 #define KEYCODE_NEXTOBJECT 0x63 //c 68 #define KEYCODE_PREVOBJECT 0x78 //x 69 #define KEYCODE_NEXTPOSE 0x6E //n 70 #define KEYCODE_PREVPOSE 0x62 //b 72 #define KEYCODE_HELP 0x68 //h 74 #define KEYCODE_NEXT_RESULT 0x71 //q 75 #define KEYCODE_PREV_RESULT 0x77 //w 76 #define KEYCODE_VIZ_SELECTED_RESULT 0x65 //e 77 #define KEYCODE_VIZ_ALL_RESULTS 0x72 //r 97 std::string visualization_topic;
101 ISM::TableHelperPtr table_helper;
104 table_helper = ISM::TableHelperPtr(
new ISM::TableHelper(
db_filename_));
105 if(!table_helper->modelDataExists())
107 ISM::printRed(
"The database \"" +
db_filename_ +
"\" doesn't contain a model!\n");
115 throw std::runtime_error(
"No db specified");
159 ISM::printYellow(
"Recognize scene for object set:\n");
171 ROS_INFO_STREAM(
"-----------------------------------------------------------");
172 ROS_INFO_STREAM(
"Calculating scene recognition results. Please wait.");
174 struct timeval start, end;
176 gettimeofday(&start, NULL);
181 gettimeofday(&end, NULL);
183 long recTime, seconds, useconds;
184 seconds = end.tv_sec - start.tv_sec;
185 useconds = end.tv_usec - start.tv_usec;
186 recTime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
198 ISM::printBlue(
"********** Vote and Score Details ************\n");
200 ISM::printBlue(
"**********************************************\n\n");
206 ROS_INFO_STREAM(
"-----------------------------------------------------------");
223 ISM::printBlue(
"\tBUFFER VOTES\n");
227 ISM::printBlue(
"\tDRAW VOTES\n");
232 ISM::printBlue(
"\tBUFFER SCENE\n");
239 ISM::printBlue(
"\tNEXT REFERENCE\n");
244 ISM::printBlue(
"\tPREVIOUS REFERENCE\n");
249 ISM::printBlue(
"\tNEXT OBJECT\n");
253 ISM::printBlue(
"\tPREVIOUS OBJECT\n");
257 ISM::printBlue(
"\tNEXT POSE\n");
261 ISM::printBlue(
"\tPREVIOUS POSE\n");
267 ISM::printBlue(
"\tRESULT: ");
276 ISM::printBlue(
"\tRESULT: ");
285 ISM::printBlue(
"\tVISUALIZE RESULT: ");
293 ISM::printBlue(
"\tVISUALIZE ALL RESULTS\n");
368 if (configuration_folder_path_.empty())
372 if (object_set->objects.size() > 0)
374 std::ofstream myfile;
375 std::string filePath = configuration_folder_path_ +
"/" +
"configuration_" + std::to_string(configuration_file_counter_++) +
".xml";
376 myfile.open(filePath);
377 myfile <<
"<Objects>";
379 for (ISM::ObjectPtr
object : object_set->objects)
381 ISM::PosePtr pose =
object->pose;
383 <<
"type=\"" <<
object->type
384 <<
"\" id=\"" <<
object->observedId
385 <<
"\" mesh=\"" <<
object->ressourcePath.string()
386 <<
"\" angles=\"quaternion\">" 387 << pose->point->eigen.x()
388 <<
"," << pose->point->eigen.y()
389 <<
"," << pose->point->eigen.z()
390 <<
"," << pose->quat->eigen.w()
391 <<
"," << pose->quat->eigen.x()
392 <<
"," << pose->quat->eigen.y()
393 <<
"," << pose->quat->eigen.z()
397 myfile <<
"</Objects>";
412 rater = ISM::RaterPtr(
new ISM::APORater(bin_size_, max_projection_angle_deviation_));
415 rater = ISM::RaterPtr(
new ISM::SimpleRater(bin_size_, max_projection_angle_deviation_));
419 std::stringstream sceneInfo;
420 sceneInfo <<
"SCENE: " << result->patternName <<
" score: " << result->confidence <<
" # of combinations: " << result->getNumberOfCombinations()<<
"\n";
421 ISM::printGreen(sceneInfo.str());
424 for(ISM::ObjectPtr o : result->recognizedSet->objects)
428 std::cout <<
"weight=" << weight <<
" expectedWeight=" << result->summarizedVotes.front().first->weightDenominator <<
"\n";
430 ISM::printYellow(
"\n####### VOTE INFORMATIONS #######\n");
431 for (ISM::SummarizedVotedPosePtr& summarizedVote : result->summarizedVotes)
433 std::stringstream voteInfo;
434 voteInfo << summarizedVote.first->source->type <<
" " << summarizedVote.first->source->observedId <<
" # of summarized votes: " << summarizedVote.second.first <<
"\n";
435 ISM::printGreen(voteInfo.str());
436 rater->printRatingAtBackProjectionLevel(summarizedVote.first, result->referencePose,
nullptr);
438 ISM::printYellow(
"#################################\n");
440 if (result->subPatterns.empty())
445 ISM::printYellow(
"\n##### SUBSCENE INFORMATIONS #####\n");
446 for (ISM::RecognitionResultPtr sub : result->subPatterns)
448 ISM::printBlue(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
449 ISM::printYellow(
"SUB");
451 ISM::printBlue(
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
453 ISM::printYellow(
"#################################\n");
466 std::vector<ISM::ObjectPtr> ret_objects;
468 for(ISM::ObjectPtr obj : result->recognizedSet->objects )
470 if( obj->type.find( result->patternName ) == std::string::npos )
472 ret_objects.push_back(obj);
477 std::vector<ISM::ObjectPtr> temp_objects;
478 for (
const ISM::RecognitionResultPtr sub_result : result->subPatterns )
481 ret_objects.insert(ret_objects.end(), temp_objects.begin(), temp_objects.end());
493 std::stringstream commands;
495 commands <<
"Additional recognizer commands:\n" 496 <<
"\tpress \"#\"\t-buffer next recognition for visualization\n" 497 <<
"\tpress \"v\"\t-show visualization of votingspace\n" 499 <<
"\tpress \"+\"\t-buffer next scene for pose prediction\n" 500 <<
"\tpress \"p\"\t-show visualization of pose prediction\n" 501 <<
"\tpress \"<\"\t-choose previous reference for pose prediction\n" 502 <<
"\tpress \"y\"\t-choose next reference for pose prediction\n" 503 <<
"\tpress \"x\"\t-choose previous object for pose prediction\n" 504 <<
"\tpress \"c\"\t-choose next object for pose prediction\n" 505 <<
"\tpress \"b\"\t-choose previous object pose for pose prediction\n" 506 <<
"\tpress \"n\"\t-choose next object pose for pose prediction\n" 508 <<
"\tpress \"q\"\t-select previous result from all results and visualize it\n" 509 <<
"\tpress \"w\"\t-select next result from all results and visualize it\n" 510 <<
"\tpress \"e\"\t-visualize selected result\n" 511 <<
"\tpress \"r\"\t-visualize all results\n";
514 ISM::printYellow(commands.str() +
"\n");
526 recogition_result_visualizer_->setSceneCount(results_buffer_.size());
527 object_model_visualizer_->drawObjectModels(
extractRealObjects(results_buffer_[selected_result_index_]));
528 recogition_result_visualizer_->addVisualization(results_buffer_[selected_result_index_]);
538 recogition_result_visualizer_->setSceneCount(results_buffer_.size());
540 for (
const ISM::RecognitionResultPtr result : results_buffer_)
543 recogition_result_visualizer_->addVisualization(result);
555 ism_pose_prediction_visualizer_->clearAllMarkerOfTopic();
556 voting_space_visualizer_->clearAllMarkerOfTopic();
557 recogition_result_visualizer_->clearAllMarkerOfTopic();
563 ISM::printBlue(
"\tPREDICT SCENE\n");
565 if(valid_position_vis_)
567 pose_predictor_->enableRandom(std::sqrt(1.0 / 3.0) * bin_size_ * 0.5, max_projection_angle_deviation_);
569 if(object_set_buffer_->objects.size() == 0)
571 ROS_ERROR(
"No Objects in scenebuffer, skipping prediction visualization.");
575 ISM::TableHelperPtr table_helper = ISM::TableHelperPtr(
new ISM::TableHelper(db_filename_));
576 std::set<std::string> all_objects_in_pattern = table_helper->getObjectsInPattern(results_buffer_[scene_counter_]->patternName);
578 pose_prediction_ism::FoundObjects fos;
579 for(std::size_t i = 0; i < object_set_buffer_->objects.size(); i++)
581 asr_msgs::AsrObject asr_o;
582 asr_o.type = object_set_buffer_->objects[i]->type;
583 asr_o.identifier = object_set_buffer_->objects[i]->observedId;
584 all_objects_in_pattern.erase(object_set_buffer_->objects[i]->type + object_set_buffer_->objects[i]->observedId);
585 fos.push_back(asr_o);
589 if(all_objects_in_pattern.size() == 0)
591 ROS_INFO(
"Scene complete, nothing to predict.");
594 pose_predictor_->setFoundObjects(fos);
595 ISM::PosePtr referencePosePtr = results_buffer_[
scene_counter_]->referencePose;
596 pose_predictor_->predictUnfoundPoses(referencePosePtr, results_buffer_[scene_counter_]->patternName, pose_prediction_sampel_faktor_);
597 pose_prediction_ism::AttributedPointCloud current_point_cloud = pose_predictor_->getAttributedPointCloud();
598 ism_pose_prediction_visualizer_->addVisualization(results_buffer_[scene_counter_], current_point_cloud, valid_position_vis_);
599 if(valid_position_vis_)
601 pose_predictor_->disableRandom();
612 voting_space_visualizer_->releaseCallback();
613 ism_pose_prediction_visualizer_->releaseCallback();
615 voting_space_visualizer_ = VIZ::ISMVotingVisualizerRVIZPtr(
new VIZ::ISMVotingVisualizerRVIZ(visualization_publisher_, bin_size_,
ros::NodeHandle(nh_.
getNamespace() +
"/voting_visualizer/")));
616 ism_pose_prediction_visualizer_ = VIZ::ISMPosePredictionVisualizerRVIZPtr(
new VIZ::ISMPosePredictionVisualizerRVIZ(visualization_publisher_, bin_size_, max_projection_angle_deviation_, object_type_to_ressource_path_map_,
619 object_model_visualizer_ =
new VIZ::ObjectModelVisualizerRVIZ(visualization_publisher_, base_frame_,
"", config.capture_interval);
621 pose_prediction_sampel_faktor_ = config.posePredictionSampelFaktor;
622 valid_position_vis_ = config.validPositionVis;
633 if (!nh_.
getParam(
"dbfilename", db_filename_))
639 if (!nh_.
getParam(
"baseFrame", base_frame_))
641 base_frame_ =
"/map";
645 if (!nh_.
getParam(
"bin_size", bin_size_))
651 if (!nh_.
getParam(
"maxProjectionAngleDeviation", max_projection_angle_deviation_))
653 max_projection_angle_deviation_ = 30;
655 ROS_INFO_STREAM(
"maxProjectionAngleDeviation: " << max_projection_angle_deviation_);
657 if (!nh_.
getParam(
"maxNumberOfResultsPerPattern", max_number_of_results_per_pattern_))
659 max_number_of_results_per_pattern_ = 1;
661 ROS_INFO_STREAM(
"maxNumberOfResultsPerPattern: " << max_number_of_results_per_pattern_);
663 if (!nh_.
getParam(
"raterType", rater_type_))
669 if (!nh_.
getParam(
"enableStoringConfigToXml", enable_storing_config_to_xml_))
671 enable_storing_config_to_xml_ =
false;
673 ROS_INFO_STREAM(
"enableStoringConfigToXml: " << enable_storing_config_to_xml_);
675 if (!nh_.
getParam(
"configurationFolderPath", configuration_folder_path_))
677 configuration_folder_path_ =
"";
679 ROS_INFO_STREAM(
"configurationFolderPath: " << configuration_folder_path_);
681 if (!nh_.
getParam(
"visualization_topic", visualization_topic))
683 visualization_topic =
"";
691 int main(
int argc,
char **argv)
#define KEYCODE_NEXT_RESULT
void visualizeSelectedResult()
ISM::ObjectSetPtr object_set_buffer_
#define KEYCODE_PREVOBJECT
int selected_result_index_
std::vector< ISM::ObjectPtr > extractRealObjects(const ISM::RecognitionResultPtr result)
dynamic_reconfigure::Server< asr_ism::recognizerConfig > dyn_reconf_server_
#define KEYCODE_NEXTOBJECT
int main(int argc, char **argv)
VIZ::ISMResultVisualizerRVIZPtr recogition_result_visualizer_
pose_prediction_ism::PosePredictor * pose_predictor_
unsigned int configuration_file_counter_
void printAdditionalResultInformation(ISM::RecognitionResultPtr &result)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ISM::RecognizerPtr ism_recognizer_
VIZ::ISMVotingVisualizerRVIZPtr voting_space_visualizer_
void printAdditionalHelpText()
#define KEYCODE_VISUALIZE
size_t number_of_objects_
#define KEYCODE_VIZ_ALL_RESULTS
VIZ::ObjectModelVisualizerRVIZ * object_model_visualizer_
#define KEYCODE_VIZ_SELECTED_RESULT
VIZ::ISMPosePredictionVisualizerRVIZPtr ism_pose_prediction_visualizer_
#define KEYCODE_PREDICTSCENE
ROSCPP_DECL void spin(Spinner &spinner)
ros::Publisher visualization_publisher_
SceneConfigurator * scene_configurator_
bool getAutomaticProcessingActive()
void recognizeScene(ISM::ObjectSetPtr object_set)
void visualizeAllResults()
#define KEYCODE_BUFFERSCENE
std::vector< ISM::RecognitionResultPtr > results_buffer_
void getNodeParameters(std::string &visualization_topic)
const std::string & getNamespace() const
void clearAllMarker()
clearAllMarker
#define KEYCODE_PREV_RESULT
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
double max_projection_angle_deviation_
#define ROS_DEBUG_STREAM(args)
void processKeyboardInput(int key)
bool enable_storing_config_to_xml_
#define KEYCODE_BUFFERVOTES
#define ROS_INFO_STREAM(args)
std::string configuration_folder_path_
bool getParam(const std::string &key, std::string &s) const
double pose_prediction_sampel_faktor_
void storeObjectsToXML(ISM::ObjectSetPtr object_set)
void dynamicReconfCallback(asr_ism::recognizerConfig &config, uint32_t level)
std::map< std::string, boost::filesystem::path > object_type_to_ressource_path_map_
void processObjectInput(ISM::ObjectPtr object)
int max_number_of_results_per_pattern_