Simple object recognition library for 2D images, with the additional functionality of projecting matched 2D objects to 3D pointclouds. A matching alogrithm is used underneath.
custom_landmark_2d is a simple object recognition library for 2D images, with the additional functionality of projecting matched 2D objects to 3D pointclouds. A matching alogrithm is used underneath.
custom_landmark_2d::Matcher is the main API. It finds all the matched objects (each represented as a 'frame' by custom_landmark_2d::Frame) in the given rgb image. Given an additional registered depth image, it can also project the matched objects into 3D pointclouds.
custom_landmark_2d::Matcher matcher; matcher.set_template(templ); matcher.set_cam_model(camera_info); // this is the threshold for ALL acceptable matching frames, // with value ranging from 0.0 to 1.0(perfect match). The default value is 0.68. // this value is likely needed to be adjusted for optimal results on different objects. matcher.match_limit = 0.6; // we want to find out how many matched objects are in the rgb image: std::vector<custom_landmark_2d::Frame> lst; if (matcher.Match(rgb_image, &lst)) { // we get >=1 matched frames/objects } // we now want the pointcloud containing only the second matched object: custom_landmark_2d::Frame object_frame = lst[1]; pcl::PointCloud<pcl::PointXYZRGB>::Ptr object_cloud; matcher.FrameToCloud(rgb_image, depth_image, object_frame, object_cloud); // we don't care about 2D points; // just directly give us all matched objects, each in a pointcloud: std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> object_clouds; if (matcher.Match(rgb_image, depth_image, &object_cloud)) { // we get >=1 matched objects }
The demo_main.cpp is provided in the package to help examine and visualize the results. It listens to two sensor_msgs::Image topics and output an annotated version of the rgb scene to /image_out as well as a concatenated pointcloud containing all matched objects to /generated_cloud. Many extra useful info is printed through ROS_INFO. You can run the demo in this way:
$ rosrun custom_landmark_2d demo template.jpg rgb:=/topic1 depth:=/topic2 cam_info:=/topic3
Note that matcher.match_limit is already set as a rosparam in demo_main.cpp, and you can easily tweak its value by typing in terminal:
$ rosparam set match_limit [new_value]
To make your life easier, two launch files, demo_pr2.launch and demo_fetch.launch are also included in the package, where topic remapping is coded up for you (you can check the exact remapping by looking into the files). You can run them like this:
$ roslaunch custom_landmark_2d demo_pr2.launch template:=[absolute_path_of_template_file]
The template_fetcher.cpp is provided in the package to help saving a template image to current folder from a sensor_msgs::Image topic. You most likely need to crop it manually afterward. You can run the template_fetcher in this way:
$ rosrun custom_landmark_2d template_fetcher rgb:=/topic1