23 #include <OGRE/Ogre.h> 24 #include <OGRE/OgreException.h> 25 #include <OGRE/OgreRoot.h> 28 #include <OGRE/OgreLight.h> 32 #include <ros_uri/ros_uri.hpp> 34 #include <pcl/common/common.h> 35 #include <pcl/point_cloud.h> 37 #include <pcl/point_types.h> 38 #include <pcl/features/integral_image_normal.h> 39 #include <pcl/common/transforms.h> 40 #include <pcl/filters/voxel_grid.h> 42 #include <asr_halcon_bridge/halcon_image.h> 48 #include <rapidxml.hpp> 49 #include <rapidxml_utils.hpp> 64 double far_plane = 100;
65 double near_plane = 0.01;
66 double cx = 648.95153;
67 double cy = 468.29311;
68 double fx = 1689.204742;
69 double fy = 1689.204742;
70 double image_width = 1292.0;
71 double image_height = 964.0;
72 int render_width = 800;
73 int render_height = 600;
81 nh_.
getParam(
"pose_val_image_height", image_height);
82 nh_.
getParam(
"pose_val_render_image_width", render_width);
83 nh_.
getParam(
"pose_val_render_image_height", render_height);
102 boost::filesystem::path dir(path.c_str());
103 boost::filesystem::create_directory(dir);
113 if (
config_.usePoseValidation) {
114 pose_val_ =
PoseValidation(image_width, image_height, far_plane, near_plane, cx, cy, fx, fy, render_width, render_height);
118 ROS_DEBUG_STREAM(
"Pose validation initialized");
145 ROS_DEBUG_STREAM(
"ROS services and publishers initialized");
147 ROS_INFO_STREAM(
"TO RECOGNIZE A NEW OBJECT CALL THE FOLLOWING SERVICE: " << std::endl <<
148 " /asr_descriptor_surface_based_recognition/get_recognizer <object_type_name> <instance_number> <use_pose_validation>" << std::endl <<
149 " TO END RECOGNITION FOR A SPECIFIC OBJECT CALL: " << std::endl <<
150 " /asr_descriptor_surface_based_recognition/release_recognizer <object_type_name>" << std::endl <<
151 " TO END RECOGNITION FOR ALL OBJECTS OF A TOPIC CALL: " << std::endl <<
152 " /asr_descriptor_surface_based_recognition/clear_all_recognizers" << std::endl <<
153 " TO GET A LIST OF ALL OBJECTS IT IS CURRENTLY SEARCHED FOR CALL: " << std::endl <<
154 " /asr_descriptor_surface_based_recognition/get_object_list");
158 std::string name = req.object_name;
159 int count = req.count;
160 if ((count < 1) || (count > 10)) {
163 bool use_pose_val = req.use_pose_val;
166 res.object_name = name;
172 std::string name = req.object_name;
178 std::vector<std::string> object_names;
179 for (std::vector<ObjectDescriptor>::iterator iter =
objects_.begin(); iter !=
objects_.end(); ++iter) {
180 object_names.push_back(iter->getName());
182 res.objects = object_names;
194 asr_object_database::RecognizerListMeshes objectMeshes;
198 std::vector<std::string> mesh_paths = objectMeshes.response.meshes;
199 for (std::vector<std::string>::iterator iter = mesh_paths.begin(); iter != mesh_paths.end(); ++iter) {
205 asr_object_database::ObjectMetaData objectType;
206 objectType.request.object_type = name;
209 if (objectType.response.is_valid) {
210 std::string object_name = name;
211 std::string xml_path = ros_uri::absolute_path(objectType.response.object_folder) +
"/" + name +
".xml";
214 rapidxml::file<> xmlFile(xml_path.c_str());
215 rapidxml::xml_document<> doc;
216 doc.parse<0>(xmlFile.data());
218 rapidxml::xml_node<> *first_node = doc.first_node();
220 rapidxml::xml_node<> *node_name = first_node->first_node(
"name");
222 object_name = node_name->value();
226 }
catch(std::runtime_error err) {
227 ROS_DEBUG_STREAM(
"Can't parse meta-xml-file (add_object -> name). error: " << err.what());
228 }
catch (rapidxml::parse_error err) {
229 ROS_DEBUG_STREAM(
"Can't parse meta-xml-file (add_object -> name). error: " << err.what());
232 bool object_in_list =
false;
233 for (
unsigned int i = 0; i <
objects_.size(); i++) {
234 if (
objects_.at(i).getName() == object_name) {
235 if (
objects_.at(i).getInstanceCount() != count) {
238 if (
objects_.at(i).getUsePoseVal() != use_pose_val) {
239 objects_.at(i).setUsePoseVal(use_pose_val);
241 object_in_list =
true;
245 if (!object_in_list) {
246 ObjectDescriptor object(objectType.response.object_folder +
"/", xml_path, count, use_pose_val);
247 if (
object.isValid()) {
262 for (
unsigned int i = 0; i <
objects_.size(); i++) {
263 if (
objects_.at(i).getName() == name) {
283 pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_with_guppy_ptr (
new pcl::PointCloud<pcl::PointXYZ>);
284 pcl::fromROSMsg(*input_point_cloud_with_guppy, *point_cloud_with_guppy_ptr);
286 HalconCpp::HImage scene_image = *halcon_bridge::toHalconCopy(input_image_guppy)->image;
287 HalconCpp::HImage scene_image_mono = *halcon_bridge::toHalconCopy(input_image_guppy_mono)->image;
290 std::string object_list =
"[";
291 for (
unsigned int i = 0; i <
objects_.size(); i++) {
295 object_list +=
objects_.at(i).getName();
301 std::vector<PoseRecognition*> pose_recs;
302 for (
unsigned int i = 0; i <
objects_.size(); i++) {
303 HalconCpp::HImage scene_image_curr = scene_image;
304 HalconCpp::HImage scene_image_mono_curr = scene_image_mono;
308 HalconCpp::HRegion region;
313 HalconCpp::HRegion region_curr;
315 region = region.Union2(region_curr);
318 scene_image_curr = scene_image_curr.ReduceDomain(region);
319 scene_image_mono_curr = scene_image_mono_curr.ReduceDomain(region);
330 for (
unsigned int i = 0; i < pose_recs.size(); i++) {
341 for (
unsigned int i = 0; i < pose_recs.size(); i++) {
342 if (
objects_.at(i).getUsePoseVal()) {
343 for (
unsigned int j = 0; j < pose_recs.at(i)->getResults().size(); j++) {
344 if (pose_recs.at(i)->getResults().at(j)->checkModelFound()) {
346 if (matrix_tuple.Length() > 0) {
347 HalconCpp::HHomMat2D matrix;
348 matrix.SetFromTuple(matrix_tuple);
350 pose_recs.at(i)->getResults().at(j)->setModelFound(
false);
351 pose_recs.at(i)->getResults().at(j)->setPoseValid(
false);
352 ROS_DEBUG_STREAM(
"Found homography of object " <<
objects_.at(i).getName() <<
" (instance " << j <<
") in the validation image does not match the homography found in the scene");
355 ROS_DEBUG_STREAM(
"Object " <<
objects_.at(i).getName() <<
" (instance " << j <<
") could not be found in the validation image");
356 if (
config_.aggressivePoseValidation) {
357 ROS_DEBUG_STREAM(
"Object " <<
objects_.at(i).getName() <<
" (instance " << j <<
") is set as invalid due to the aggressive validation strategy");
358 pose_recs.at(i)->getResults().at(j)->setModelFound(
false);
359 pose_recs.at(i)->getResults().at(j)->setPoseValid(
false);
380 for (
unsigned int i = 0; i < pose_recs.size(); i++) {
381 std::string name = pose_recs.at(i)->getObjectDescriptor()->getName();
382 std::string mesh_path = pose_recs.at(i)->getObjectDescriptor()->getMesh();
384 if (
config_.useVisualisationColor) {
389 for (
unsigned int j = 0; j < pose_recs.at(i)->getResults().size(); j++) {
390 if (pose_recs.at(i)->getResults().at(j)->checkModelFound()) {
391 asr_msgs::AsrObjectPtr
object =
createAsrMessage(pose_recs.at(i), j, input_point_cloud_with_guppy->header);
392 geometry_msgs::PoseWithCovariance obj_pose =
object->sampledPoses.front();
394 HalconCpp::HQuaternion quat;
395 HalconCpp::HTuple quat_tuple = HalconCpp::HTuple::TupleGenConst(4, 0);
396 quat_tuple[0] = obj_pose.pose.orientation.w;
397 quat_tuple[1] = obj_pose.pose.orientation.x;
398 quat_tuple[2] = obj_pose.pose.orientation.y;
399 quat_tuple[3] = obj_pose.pose.orientation.z;
400 quat.SetFromTuple(quat_tuple);
402 double axis_x_x, axis_x_y, axis_x_z;
403 axis_x_x = quat.QuatRotatePoint3d(1, 0, 0, &axis_x_y, &axis_x_z);
404 double axis_y_x, axis_y_y, axis_y_z;
405 axis_y_x = quat.QuatRotatePoint3d(0, 1, 0, &axis_y_y, &axis_y_z);
406 double axis_z_x, axis_z_y, axis_z_z;
407 axis_z_x = quat.QuatRotatePoint3d(0, 0, 1, &axis_z_y, &axis_z_z);
409 outstream_poses_ <<
object->type <<
"_" <<
object->identifier <<
";" << obj_pose.pose.position.x <<
";" << obj_pose.pose.position.y <<
";" << obj_pose.pose.position.z <<
";" << obj_pose.pose.orientation.w <<
";" << obj_pose.pose.orientation.x <<
";" << obj_pose.pose.orientation.y <<
";" << obj_pose.pose.orientation.z <<
";" << pose_recs.at(i)->getResults().at(j)->getScore2D() <<
";" << pose_recs.at(i)->getResults().at(j)->getScore3D() <<
";" << axis_x_x <<
";" << axis_x_y <<
";" << axis_x_z <<
";" << axis_y_x <<
";" << axis_y_y <<
";" << axis_y_z <<
";" << axis_z_x <<
";" << axis_z_y <<
";" << axis_z_z <<
"#";
411 ROS_INFO_STREAM(
"------- " << name <<
" found: " << obj_pose.pose.position.x <<
" " << obj_pose.pose.position.y <<
" " << obj_pose.pose.position.z <<
" " << obj_pose.pose.orientation.w <<
" " << obj_pose.pose.orientation.x <<
" " << obj_pose.pose.orientation.y <<
" " << obj_pose.pose.orientation.z <<
"; score 2D: " << pose_recs.at(i)->getResults().at(j)->getScore2D() <<
", score 3D: " << pose_recs.at(i)->getResults().at(j)->getScore3D());
413 positions.
addPosition(pose_recs.at(i)->getResults().at(j)->getTexPoint(), pose_recs.at(i)->getResults().at(j)->getSearchRadius());
416 if (pose_recs.at(i)->getResults().at(j)->getPoseValid()) {
417 ROS_INFO_STREAM(
"------- " << name <<
" not found but texture found with score: " << pose_recs.at(i)->getResults().at(j)->getScore2D());
427 pcl::PointCloud<pcl::PointXYZRGB>::Ptr result_cloud =
createVisualizationCloud(pose_recs, input_point_cloud_with_guppy->header);
429 sensor_msgs::PointCloud2 reduced_cloud_sensor_msg;
437 halcon_bridge::HalconImagePtr ptr = boost::make_shared<halcon_bridge::HalconImage>();
438 ptr->image =
new HalconCpp::HImage();
439 if (
config_.useVisualisationColor) {
440 ptr->header = input_image_guppy->header;
441 ptr->encoding = input_image_guppy->encoding;
442 *ptr->image = scene_image;
444 ptr->header = input_image_guppy_mono->header;
445 ptr->encoding = input_image_guppy_mono->encoding;
446 *ptr->image = scene_image_mono;
448 sensor_msgs::ImagePtr result = ptr->toImageMsg();
454 ROS_INFO_STREAM(
"Time for pose validation: " << validation_duration <<
" seconds");
472 std::cout << std::endl;
474 for (
unsigned int i = 0; i <
objects_.size(); i++) {
475 delete pose_recs.at(i);
495 HalconCpp::HPose pose;
496 pose.SetFromTuple(pose_rec->
getResults().at(results_index)->getPose());
497 HalconCpp::HQuaternion quaternion;
498 quaternion.PoseToQuat(pose);
499 quaternion = quaternion.QuatCompose(pose_rec->
getResults().at(results_index)->getAdjustedRotation());
501 asr_msgs::AsrObjectPtr object;
502 object.reset(
new asr_msgs::AsrObject());
504 object->header = header;
505 object->providedBy =
"descriptor_surface_based_recognition";
507 geometry_msgs::Pose current_pose;
509 current_pose.position.x = (double)pose.ConvertToTuple()[0];
510 current_pose.position.y = (double)pose.ConvertToTuple()[1];
511 current_pose.position.z = (double)pose.ConvertToTuple()[2];
513 current_pose.orientation.w = (double)quaternion.ConvertToTuple().ToDArr()[0];
514 current_pose.orientation.x = (double)quaternion.ConvertToTuple().ToDArr()[1];
515 current_pose.orientation.y = (double)quaternion.ConvertToTuple().ToDArr()[2];
516 current_pose.orientation.z = (double)quaternion.ConvertToTuple().ToDArr()[3];
518 geometry_msgs::PoseWithCovariance current_pose_with_c;
519 current_pose_with_c.pose = current_pose;
520 for(
unsigned int i = 0; i < current_pose_with_c.covariance.size(); i++)
521 current_pose_with_c.covariance.at(i) = 0.0f;
523 object->sampledPoses.push_back(current_pose_with_c);
526 boost::array< ::geometry_msgs::Point_<std::allocator<void> > , 8> bounding_box;
527 for (
unsigned int z = 0;
z < 2;
z++) {
528 for (
unsigned int y = 0;
y < 2;
y++) {
529 for (
unsigned int x = 0;
x < 2;
x++) {
530 bounding_box[4 *
z + 2 *
y +
x].x = (double)bounding_corners[
x * 3];
531 bounding_box[4 *
z + 2 *
y +
x].y = (double)bounding_corners[
y * 3 + 1];
532 bounding_box[4 *
z + 2 *
y +
x].z = (double)bounding_corners[
z * 3 + 2];
536 object->boundingBox = bounding_box;
538 object->colorName =
"textured";
541 object->identifier = boost::lexical_cast<std::string>(results_index);
546 object->sizeConfidence = pose_rec->
getResults().at(results_index)->getScore3D();
547 object->typeConfidence = pose_rec->
getResults().at(results_index)->getScore2D();
554 visualization_msgs::Marker marker;
555 marker.header =
object->header;
556 marker.ns =
"Recognition results";
558 marker.action = visualization_msgs::Marker::ADD;
559 marker.pose.position =
object->sampledPoses.front().pose.position;
561 marker.pose.orientation =
object->sampledPoses.front().pose.orientation;
567 marker.scale.x = 0.001;
568 marker.scale.y = 0.001;
569 marker.scale.z = 0.001;
571 marker.mesh_use_embedded_materials =
true;
572 marker.type = visualization_msgs::Marker::MESH_RESOURCE;
573 marker.mesh_resource = mesh_path;
602 visualization_msgs::Marker marker;
603 marker.header = header;
604 marker.ns =
"Result Bounding Boxes";
606 marker.action = visualization_msgs::Marker::ADD;
608 marker.pose.orientation.w = 1.0;
609 marker.type = visualization_msgs::Marker::LINE_LIST;
611 marker.scale.x = 0.01;
613 marker.color.r = color.
r;
614 marker.color.g = color.
g;
615 marker.color.b = color.
b;
616 marker.color.a = 1.0;
620 geometry_msgs::Point p;
626 marker.points.push_back(p);
628 marker.points.push_back(p);
631 marker.points.push_back(p);
633 marker.points.push_back(p);
636 marker.points.push_back(p);
638 marker.points.push_back(p);
641 marker.points.push_back(p);
643 marker.points.push_back(p);
646 if (drawCompleteBoxes) {
651 marker.points.push_back(p);
653 marker.points.push_back(p);
656 marker.points.push_back(p);
658 marker.points.push_back(p);
661 marker.points.push_back(p);
663 marker.points.push_back(p);
666 marker.points.push_back(p);
668 marker.points.push_back(p);
675 marker.points.push_back(p);
677 marker.points.push_back(p);
683 marker.points.push_back(p);
685 marker.points.push_back(p);
691 marker.points.push_back(p);
693 marker.points.push_back(p);
699 marker.points.push_back(p);
701 marker.points.push_back(p);
710 const int BOX_BORDER_SIZE =
config_.boundingBoxBorderSize;
711 const int ORIENTATION_TRIANGLE_SIZE =
config_.orientationTriangleSize;
712 const int POINTS_RADIUS =
config_.featurePointsRadius;
714 HalconCpp::HTuple color_points, color_box;
715 if (
config_.useVisualisationColor) {
716 color_points.Append(
config_.visualisationColorPointsRed);
717 color_points.Append(
config_.visualisationColorPointsGreen);
718 color_points.Append(
config_.visualisationColorPointsBlue);
719 color_box.Append(
config_.visualisationColorBoxRed);
720 color_box.Append(
config_.visualisationColorBoxGreen);
721 color_box.Append(
config_.visualisationColorBoxBlue);
723 color_points.Append(255);
724 color_box.Append(255);
727 for (
unsigned int i = 0; i < pose_rec->
getResults().size(); i++) {
730 HalconCpp::HTuple row, column;
731 HalconCpp::HRegion search_points;
732 for (
unsigned int k = 0; k <= i; k++) {
735 search_points.GenCircle(row, column, HalconCpp::HTuple::TupleGenConst(row.Length(), POINTS_RADIUS));
736 *scene_image = search_points.PaintRegion(*scene_image, color_points, HalconCpp::HTuple(
"fill"));
737 }
catch(HalconCpp::HException exc) {
743 HalconCpp::HRegion bounding_box;
744 bounding_box.GenRegionPoints(row, column);
745 Hlong row1, column1, row2, column2;
746 bounding_box.SmallestRectangle1(&row1, &column1, &row2, &column2);
748 HalconCpp::HTuple rows, columns;
750 double upperLeftInnerX, upperRightInnerX, lowerRightInnerX, lowerLeftInnerX;
751 double upperLeftInnerY, upperRightInnerY, lowerRightInnerY, lowerLeftInnerY;
753 upperLeftInnerX = upperLeftInnerX / temp;
754 upperLeftInnerY = upperLeftInnerY / temp;
755 rows.Append((
int)upperLeftInnerX);
756 columns.Append((
int)upperLeftInnerY);
759 rows.Append((
int)(upperRightInnerX / temp));
760 columns.Append((
int)(upperRightInnerY / temp));
763 rows.Append((
int)(lowerRightInnerX / temp));
764 columns.Append((
int)(lowerRightInnerY / temp));
767 rows.Append((
int)(lowerLeftInnerX / temp));
768 columns.Append((
int)(lowerLeftInnerY / temp));
770 rows.Append((
int)upperLeftInnerX);
771 columns.Append((
int)upperLeftInnerY);
773 HalconCpp::HRegion inner_box;
774 inner_box.GenRegionPolygonFilled(rows, columns);
776 HalconCpp::HTuple rows_outer, columns_outer;
778 double upperLeftOuterX, upperRightOuterX, lowerRightOuterX, lowerLeftouterX;
779 double upperLeftOuterY, upperRightOuterY, lowerRightOuterY, lowerLeftOuterY;
781 upperLeftOuterX = upperLeftOuterX / temp_outer;
782 upperLeftOuterY = upperLeftOuterY / temp_outer;
783 rows_outer.Append((
int)upperLeftOuterX);
784 columns_outer.Append((
int)upperLeftOuterY);
787 rows_outer.Append((
int)(upperRightOuterX / temp_outer));
788 columns_outer.Append((
int)(upperRightOuterY / temp_outer));
791 rows_outer.Append((
int)(lowerRightOuterX / temp_outer));
792 columns_outer.Append((
int)(lowerRightOuterY / temp_outer));
795 rows_outer.Append((
int)(lowerLeftouterX / temp_outer));
796 columns_outer.Append((
int)(lowerLeftOuterY / temp_outer));
798 rows_outer.Append((
int)upperLeftOuterX);
799 columns_outer.Append((
int)upperLeftOuterY);
801 HalconCpp::HRegion outer_box;
802 outer_box.GenRegionPolygonFilled(rows_outer, columns_outer);
804 inner_box = outer_box.Difference(inner_box);
806 *scene_image = inner_box.PaintRegion(*scene_image, color_box, HalconCpp::HTuple(
"fill"));
811 inner_box.SmallestRectangle1(&r, &c, &r2, &c2);
812 int max_expansion = r2 - r;
813 if (c2 - c > max_expansion) {
814 max_expansion = c2 - c;
816 pose_rec->
getResults().at(i)->setSearchRadius((
int)(max_expansion * 0.5));
822 double triLeftX, triRightX, triUpX;
823 double triLeftY, triRightY, triUpY;
824 triLeftX = pose_rec->
getResults().at(i)->getTransMatrix2D().ProjectiveTransPoint2d(ORIENTATION_TRIANGLE_SIZE, -1 * ORIENTATION_TRIANGLE_SIZE, 1.0, &triLeftY, &temp);
825 triLeftX = triLeftX / temp;
826 triLeftY = triLeftY / temp;
827 rows.Append((
int)triLeftX);
828 columns.Append((
int)triLeftY);
830 triRightX = pose_rec->
getResults().at(i)->getTransMatrix2D().ProjectiveTransPoint2d(ORIENTATION_TRIANGLE_SIZE, ORIENTATION_TRIANGLE_SIZE, 1.0, &triRightY, &temp);
831 rows.Append((
int)(triRightX / temp));
832 columns.Append((
int)(triRightY / temp));
834 triUpX = pose_rec->
getResults().at(i)->getTransMatrix2D().ProjectiveTransPoint2d(-2.5 * ORIENTATION_TRIANGLE_SIZE, 0, 1.0, &triUpY, &temp);
835 rows.Append((
int)(triUpX / temp));
836 columns.Append((
int)(triUpY / temp));
838 rows.Append((
int)triLeftX);
839 columns.Append((
int)triLeftY);
841 HalconCpp::HRegion orientation_triangle;
842 orientation_triangle.GenRegionPolygonFilled(rows, columns);
843 *scene_image = orientation_triangle.PaintRegion(*scene_image, color_box, HalconCpp::HTuple(
"fill"));
850 pcl::PointCloud<pcl::PointXYZRGB>::Ptr result_cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
853 for (
unsigned int i = 0; i < pose_recs.size(); i++) {
854 for(
unsigned int j = 0; j < pose_recs.at(i)->getResults().size(); j++) {
855 if (pose_recs.at(i)->getResults().at(j)->checkModelFound()) {
860 std::vector<rgb> colors;
861 if (num_colors > 0) {
862 for(
int i = 0; i < 360; i += 360 / num_colors) {
877 for (
unsigned int i = 0; i < pose_recs.size(); i++) {
878 for(
unsigned int j = 0; j < pose_recs.at(i)->getResults().size(); j++) {
879 if (pose_recs.at(i)->getResults().at(j)->checkModelFound()) {
883 createBoxMarker(pose_recs.at(i)->getResults().at(j), header, colors.at(counter),
config_.drawCompleteCloudBoxes);
886 pcl::PointCloud<pcl::PointXYZRGB>::Ptr tmp(
new pcl::PointCloud<pcl::PointXYZRGB>);
887 pcl::copyPointCloud(*(pose_recs.at(i)->getResults().at(j)->getSearchCloud()), *tmp);
889 for(
unsigned int j = 0; j < tmp->width * tmp->height; j++) {
890 tmp->points[j].r = colors.at(counter).r * 255;
891 tmp->points[j].g = colors.at(counter).g * 255;
892 tmp->points[j].b = colors.at(counter).b * 255;
894 *result_cloud += *tmp;
896 counter = (counter + 1) % colors.size();
903 pcl::PointXYZRGB point;
907 result_cloud->push_back(point);
918 ros::init (argc, argv,
"asr_descriptor_surface_based_recognition");
void wait(size_t task_threshold=0) const
boost::shared_ptr< ApproximateSync > sync_policy_
std::string image_color_topic_
std::vector< RecognitionResult * > getResults() const
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
static const std::string OUTPUT_EVALUATION_FILE_TIME("global_times.txt")
ros::ServiceServer get_object_list_service_
std::string output_objects_topic_
static const std::string RELEASE_RECOGNIZER_SERVICE_NAME("release_recognizer")
bool compareHomographyMatrices(HalconCpp::HHomMat2D original, HalconCpp::HHomMat2D rendered, int pose_validation_dist_err)
Compares the given matrices and returns whether they describe the same projection.
bool processReleaseRecognizerRequest(ReleaseRecognizer::Request &req, ReleaseRecognizer::Response &res)
bool processGetObjectListRequest(GetObjectList::Request &req, GetObjectList::Response &res)
void createMarker(asr_msgs::AsrObjectPtr &object, std::string &mesh_path)
Adds a marker which indicates the pose of the found object to the array containing all found markers ...
pcl::PointCloud< pcl::PointXYZRGB >::Ptr createVisualizationCloud(std::vector< PoseRecognition * > &pose_recs, std_msgs::Header header)
Creates a single, colored point cloud from the reduced point clouds which were used to recognize the ...
HalconCpp::HSurfaceModel getSurfaceModel() const
void publish(const boost::shared_ptr< M > &message) const
static const std::string OUTPUT_EVALUATION_FILE_POSES("global_poses.txt")
void addPosition(Eigen::Vector2i position, int search_radius)
Adds a new object instance position to the list.
dynamic_reconfigure::Server< DescriptorSurfaceBasedRecognitionConfig > reconfigure_server_
visualization_msgs::MarkerArrayPtr msgs_box_marker_array_
static const std::string OUTPUT_EVALUATION_DIR("eval")
void configCallback(DescriptorSurfaceBasedRecognitionConfig &config_, uint32_t level)
The callback function which is called when the configuration file has changed.
std::string point_cloud_topic_
message_filters::Subscriber< sensor_msgs::Image > image_sub_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
static const std::string GET_RECOGNIZER_SERVICE_NAME("get_recognizer")
std::string image_mono_topic_
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
bool startObjectRecognition(std::string name, int count, bool use_pose_val)
Adds an object to the list of searchable objects.
void createBoxMarker(RecognitionResult *result, std_msgs::Header header, rgb color, bool drawCompleteBoxes)
Adds a bounding box marker which indicates the size of the reduced point cloud used to recognize the ...
bool schedule(task_type const &task)
boost::threadpool::pool thread_pool_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
Ogre::MeshPtr loadMeshFromResource(const std::string &resource_path)
message_filters::Subscriber< sensor_msgs::PointCloud2 > pc_with_guppy_sub_
TFSIMD_FORCE_INLINE const tfScalar & y() const
pcl::PointCloud< pcl::PointXYZ >::Ptr getSearchCloud() const
bool processGetRecognizerRequest(GetRecognizer::Request &req, GetRecognizer::Response &res)
void clearMarkers()
Clears the visualized markers of the last frame.
std::ofstream outstream_times_
ROSCPP_DECL void spin(Spinner &spinner)
ros::Publisher marker_pub_
message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::PointCloud2 > ApproximatePolicy
void threadTask(PoseRecognition *pose_rec)
The task given to each thread in the threadpool (=> Search a specific object)
fifo_pool pool
A standard pool.
std::string output_marker_bounding_box_topic_
static const std::string OBJECT_DB_SERVICE_OBJECT_TYPE("/asr_object_database/object_meta_data")
void findPoses()
Recognizes the present object instances in the scene.
ros::ServiceServer clear_all_recognizers_service_
ros::ServiceClient object_db_meshes_service_client_
bool isInitialized() const
Returns whether this object has been initialized.
ros::ServiceServer get_recognizer_service_
std::string output_cloud_topic_
ObjectDescriptor * getObjectDescriptor() const
static const std::string OBJECT_DB_SERVICE_OBJECT_MESHES("/asr_object_database/recognizer_list_meshes")
std::vector< ObjectDescriptor > objects_
TFSIMD_FORCE_INLINE const tfScalar & x() const
std::vector< ObjectViewDescriptor > getModelViewDescriptors() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::ofstream outstream_poses_
DescriptorSurfaceBasedRecognitionConfig config_
ros::Publisher cloud_pub_
#define ROS_DEBUG_STREAM(args)
ROSLIB_DECL std::string getPath(const std::string &package_name)
TFSIMD_FORCE_INLINE const tfScalar & z() const
std::string getMesh() const
std::string output_marker_topic_
rgb hsv2rgb(hsv in)
Converts the given hsv-color to rgb.
ros::ServiceServer release_recognizer_service_
std::string output_image_topic_
ros::Publisher boxes_pub_
visualization_msgs::MarkerArrayPtr msgs_marker_array_
#define ROS_INFO_STREAM(args)
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
void overlaySceneWith2DResults(PoseRecognition *pose_rec, HalconCpp::HImage *scene_image)
Paints the results of the 2D recognition (bounding box, feature points & orientation triangle) to the...
ros::Publisher image_pub_
ros::Publisher objects_pub_
static const std::string OBJECT_DATABASE_CATEGORY("descriptor")
bool getParam(const std::string &key, std::string &s) const
std::string getName() const
bool processClearAllRecognizersRequest(ClearAllRecognizers::Request &req, ClearAllRecognizers::Response &res)
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
static const std::string NODE_NAME("asr_descriptor_surface_based_recognition")
std::vector< Ogre::MeshPtr > meshes_
message_filters::Synchronizer< ApproximatePolicy > ApproximateSync
std::vector< Object2DPositions > last_frame_positions_
static const std::string GET_OBJECT_LIST_SERVICE_NAME("get_object_list")
static const std::string CLEAR_ALL_RECOGNIZERS_SERVICE_NAME("clear_all_recognizers")
void initializeMeshes()
Loads all available object meshes so they can be used later.
int main(int argc, char **argv)
asr_msgs::AsrObjectPtr createAsrMessage(PoseRecognition *pose_rec, int results_index, std_msgs::Header header)
Creates a Asr-Object-Message containing the results of a found object instance.
HalconCpp::HTuple validateObject(ObjectDescriptor *object, RecognitionResult *recognition_result, Ogre::MeshPtr mesh)
Searches the rendered image for the given object.
DescriptorSurfaceBasedRecognition()
The constructor of this class.
ros::ServiceClient object_db_service_client_
void rosCallback(const sensor_msgs::ImageConstPtr &input_image_guppy, const sensor_msgs::ImageConstPtr &input_image_guppy_mono, const sensor_msgs::PointCloud2ConstPtr &input_point_cloud_with_guppy)
The callback function for the ros subscriptions (images and point cloud; called for every new frame) ...
void stopObjectRecognition(std::string name)
Removes an object from the list of searchable objects.
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)
message_filters::Subscriber< sensor_msgs::Image > image_mono_sub_