19 #include <Eigen/Dense> 22 #include <pcl/point_cloud.h> 23 #include <pcl/filters/frustum_culling.h> 24 #include <pcl/impl/point_types.hpp> 26 #include <pcl/filters/impl/frustum_culling.hpp> 35 camera_orientation_(Eigen::Vector3d(0.0, 0.0, 1.0)) { }
37 bool Rating::ratePose(
const geometry_msgs::Pose &pose,
double threshold_d,
double threshold_x,
double threshold_y) {
46 return rating_d > threshold_d && rating_x > threshold_x && rating_y > threshold_y;
51 Eigen::Vector3d object_position(object_pose.position.x, object_pose.position.y, object_pose.position.z);
54 double dist_to_mid = std::abs(dot_cam_obj - ((
fcp_ +
ncp_) / 2.0));
55 double dist_threshold = (
fcp_ -
ncp_) / 2.0;
57 if (dist_to_mid < dist_threshold) {
58 rating = 0.5 + 0.5 * cos((dist_to_mid * M_PI) / dist_threshold);
67 Eigen::Vector3d object_position(object_pose.position.x, object_pose.position.y, object_pose.position.z);
74 object_position.y() = 0.0;
75 angle_max = (
fovx_ * M_PI) / 180.0;
80 object_position.x() = 0.0;
81 angle_max = (
fovy_ * M_PI) / 180.0;
84 object_position.normalize();
88 if (angle < angle_max) {
89 rating = 0.5 + 0.5 * std::cos((angle * M_PI) / angle_max);
96 pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud = boost::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
97 unsigned int bb_size = bounding_box.size();
98 for (
unsigned int i = 0; i < bb_size; i++) {
99 pcl::PointXYZ pt = pcl::PointXYZ(bounding_box.at(i).x, bounding_box.at(i).y, bounding_box.at(i).z);
100 point_cloud->push_back(pt);
103 pcl::FrustumCulling<pcl::PointXYZ> fc;
104 fc.setHorizontalFOV(
fovx_);
105 fc.setVerticalFOV(
fovy_);
106 fc.setNearPlaneDistance(
ncp_);
107 fc.setFarPlaneDistance(
fcp_);
112 cam << 0.0, 0.0, -1.0, 0.0,
116 fc.setCameraPose(cam);
118 fc.setInputCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr(point_cloud));
120 pcl::PointCloud<pcl::PointXYZ>::Ptr culled_cloud = boost::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
121 fc.filter(*culled_cloud);
123 return (culled_cloud->size() == bb_size);
129 Eigen::Vector3d v1, v2;
130 double angleThreshold = M_PI * 0.5;
131 v1 << object_pose.position.x, object_pose.position.y, object_pose.position.z;
135 float xNorm = v1.lpNorm<2>();
141 float best_rated = 0.0;
142 for (
unsigned int i = 0; i < normals.size(); i++) {
143 v2 << normals.at(i).x, normals.at(i).y, normals.at(i).z;
145 float yNorm = v2.lpNorm<2>();
147 float cosine = v1.dot(v2) / xNorm / yNorm;
148 float angle = std::acos(cosine);
149 if (angle < angleThreshold) {
150 float rating = 0.5 + 0.5 * std::cos(angle * M_PI / angleThreshold);
151 if (rating > best_rated) { best_rated = rating; }
159 bool Rating::rateBBandNormal(
const geometry_msgs::Pose &object_pose,
const std::array<geometry_msgs::Point, 8> &bounding_box,
const std::vector<geometry_msgs::Point> &normals,
double threshold) {
163 else if (normals.empty()) {
bool getBBRating(const std::array< geometry_msgs::Point, 8 > &bounding_box)
Returns the amount of points of the bounding box inside the frustum divided by the amount of all poin...
double getAngleRating(const geometry_msgs::Pose &object_pose, bool direction)
Returns a rating of an object's pose based on the (azimut or elevation) angle between the camera's vi...
bool rateBBandNormal(const geometry_msgs::Pose &object_pose, const std::array< geometry_msgs::Point, 8 > &bounding_box, const std::vector< geometry_msgs::Point > &normals, double threshold)
Rates an objects visibility based on its bounding box and its normals.
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
#define ROS_DEBUG_STREAM(args)
double getNormalRating(const geometry_msgs::Pose &object_pose, const std::vector< geometry_msgs::Point > &normals)
Returns a rating for the angle between sight vector to object and object's normal. 1.0 is best, 0.0 worst.
bool ratePose(const geometry_msgs::Pose &pose, double threshold_d, double threshold_x, double threshold_y)
Return whether a pose is visible in the camera frustum based on the distance and angle rating...
const Eigen::Vector3d camera_orientation_
double getDistanceRating(const geometry_msgs::Pose &object_pose)
Returns a rating of an object's pose based on the distance to the camera.
Rating(double fovx, double fovy, double ncp, double fcp)
The constructor of the class.