Skip to content

Commit

Permalink
Fix wrong update of min_points_ and max_points_
Browse files Browse the repository at this point in the history
The update of min_points_ and max_points_ happens every time the compute
method is called. If voxel_size_ is different from the standard value of
0.06, for each call to the compute method, min_points_ and max_points_ are
getting smaller (for a voxel size > 0.06). After a couple of iterations,
they are equal to zero.

It is better to set min_points_ and max_points_ outside of the compute
method, since there is no need to recalculate them every time. In
addition, min_points_ and max_points_ depends on internal knowledge of
the people tracker (the voxel_size_ and the fact, that there is only one
point per voxel after downsampling). For a user of the people tracker,
the only thing that should matter is the height and the width of a person
cluster. The cluster limits can be deduced from this information.
  • Loading branch information
moritzblume committed Apr 24, 2014
1 parent 22b5a72 commit ba2f4ca
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 38 deletions.
4 changes: 3 additions & 1 deletion people/apps/main_ground_based_people_detection.cpp
Expand Up @@ -118,6 +118,8 @@ int main (int argc, char** argv)
// Algorithm parameters:
std::string svm_filename = "../../people/data/trainedLinearSVMForPeopleDetectionWithHOG.yaml";
float min_confidence = -1.5;
float min_width = 0.1;
float max_width = 8.0;
float min_height = 1.3;
float max_height = 2.3;
float voxel_size = 0.06;
Expand Down Expand Up @@ -190,7 +192,7 @@ int main (int argc, char** argv)
people_detector.setVoxelSize(voxel_size); // set the voxel size
people_detector.setIntrinsics(rgb_intrinsics_matrix); // set RGB camera intrinsic parameters
people_detector.setClassifier(person_classifier); // set person classifier
people_detector.setHeightLimits(min_height, max_height); // set person classifier
people_detector.setPersonClusterLimits(min_height, max_height, min_width, max_width);
people_detector.setSamplingFactor(sampling_factor); // set a downsampling factor to the point cloud (for increasing speed)
// people_detector.setSensorPortraitOrientation(true); // set sensor orientation to vertical

Expand Down
36 changes: 20 additions & 16 deletions people/include/pcl/people/ground_based_people_detection_app.h
Expand Up @@ -147,22 +147,15 @@ namespace pcl
setHeadCentroid (bool head_centroid);

/**
* \brief Set minimum and maximum allowed height for a person cluster.
* \brief Set minimum and maximum allowed height and width for a person cluster.
*
* \param[in] min_height Minimum allowed height for a person cluster (default = 1.3).
* \param[in] max_height Maximum allowed height for a person cluster (default = 2.3).
* \param[in] min_width Minimum width for a person cluster (default = 0.1).
* \param[in] max_width Maximum width for a person cluster (default = 8.0).
*/
void
setHeightLimits (float min_height, float max_height);

/**
* \brief Set minimum and maximum allowed number of points for a person cluster.
*
* \param[in] min_points Minimum allowed number of points for a person cluster.
* \param[in] max_points Maximum allowed number of points for a person cluster.
*/
void
setDimensionLimits (int min_points, int max_points);
setPersonClusterLimits (float min_height, float max_height, float min_width, float max_width);

/**
* \brief Set minimum distance between persons' heads.
Expand All @@ -173,13 +166,15 @@ namespace pcl
setMinimumDistanceBetweenHeads (float heads_minimum_distance);

/**
* \brief Get minimum and maximum allowed height for a person cluster.
* \brief Get the minimum and maximum allowed height and width for a person cluster.
*
* \param[out] min_height Minimum allowed height for a person cluster.
* \param[out] max_height Maximum allowed height for a person cluster.
* \param[out] min_width Minimum width for a person cluster.
* \param[out] max_width Maximum width for a person cluster.
*/
void
getHeightLimits (float& min_height, float& max_height);
getPersonClusterLimits (float& min_height, float& max_height, float& min_width, float& max_width);

/**
* \brief Get minimum and maximum allowed number of points for a person cluster.
Expand Down Expand Up @@ -225,6 +220,12 @@ namespace pcl
void
swapDimensions (pcl::PointCloud<pcl::RGB>::Ptr& cloud);

/**
* \brief Estimates min_points_ and max_points_ based on the minimal and maximal cluster size and the voxel size.
*/
void
updateMinMaxPoints ();

/**
* \brief Perform people detection on the input data and return people clusters information.
*
Expand Down Expand Up @@ -266,6 +267,12 @@ namespace pcl
/** \brief person clusters minimum height from the ground plane */
float min_height_;

/** \brief person clusters maximum width, used to estimate how many points maximally represent a person cluster */
float max_width_;

/** \brief person clusters minimum width, used to estimate how many points minimally represent a person cluster */
float min_width_;

/** \brief if true, the sensor is considered to be vertically placed (portrait mode) */
bool vertical_;

Expand All @@ -279,9 +286,6 @@ namespace pcl
/** \brief minimum number of points for a person cluster */
int min_points_;

/** \brief true if min_points and max_points have been set by the user, false otherwise */
bool dimension_limits_set_;

/** \brief minimum distance between persons' heads */
float heads_minimum_distance_;

Expand Down
Expand Up @@ -55,9 +55,9 @@ pcl::people::GroundBasedPeopleDetectionApp<PointT>::GroundBasedPeopleDetectionAp
head_centroid_ = true;
min_height_ = 1.3;
max_height_ = 2.3;
min_points_ = 30; // this value is adapted to the voxel size in method "compute"
max_points_ = 5000; // this value is adapted to the voxel size in method "compute"
dimension_limits_set_ = false;
min_width_ = 0.1;
max_width_ = 8.0;
updateMinMaxPoints ();
heads_minimum_distance_ = 0.3;

// set flag values for mandatory parameters:
Expand Down Expand Up @@ -91,6 +91,7 @@ template <typename PointT> void
pcl::people::GroundBasedPeopleDetectionApp<PointT>::setVoxelSize (float voxel_size)
{
voxel_size_ = voxel_size;
updateMinMaxPoints ();
}

template <typename PointT> void
Expand All @@ -113,19 +114,21 @@ pcl::people::GroundBasedPeopleDetectionApp<PointT>::setSensorPortraitOrientation
vertical_ = vertical;
}

template <typename PointT> void
pcl::people::GroundBasedPeopleDetectionApp<PointT>::setHeightLimits (float min_height, float max_height)
template<typename PointT>
void pcl::people::GroundBasedPeopleDetectionApp<PointT>::updateMinMaxPoints ()
{
min_height_ = min_height;
max_height_ = max_height;
min_points_ = (int) (min_height_ * min_width_ / voxel_size_ / voxel_size_);
max_points_ = (int) (max_height_ * max_width_ / voxel_size_ / voxel_size_);
}

template <typename PointT> void
pcl::people::GroundBasedPeopleDetectionApp<PointT>::setDimensionLimits (int min_points, int max_points)
pcl::people::GroundBasedPeopleDetectionApp<PointT>::setPersonClusterLimits (float min_height, float max_height, float min_width, float max_width)
{
min_points_ = min_points;
max_points_ = max_points;
dimension_limits_set_ = true;
min_height_ = min_height;
max_height_ = max_height;
min_width_ = min_width;
max_width_ = max_width;
updateMinMaxPoints ();
}

template <typename PointT> void
Expand All @@ -141,10 +144,12 @@ pcl::people::GroundBasedPeopleDetectionApp<PointT>::setHeadCentroid (bool head_c
}

template <typename PointT> void
pcl::people::GroundBasedPeopleDetectionApp<PointT>::getHeightLimits (float& min_height, float& max_height)
pcl::people::GroundBasedPeopleDetectionApp<PointT>::getPersonClusterLimits (float& min_height, float& max_height, float& min_width, float& max_width)
{
min_height = min_height_;
max_height = max_height_;
min_width = min_width_;
max_width = max_width_;
}

template <typename PointT> void
Expand Down Expand Up @@ -239,14 +244,6 @@ pcl::people::GroundBasedPeopleDetectionApp<PointT>::compute (std::vector<pcl::pe
return (false);
}

if (!dimension_limits_set_) // if dimension limits have not been set by the user
{
// Adapt thresholds for clusters points number to the voxel size:
max_points_ = int(float(max_points_) * std::pow(0.06/voxel_size_, 2));
if (voxel_size_ > 0.06)
min_points_ = int(float(min_points_) * std::pow(0.06/voxel_size_, 2));
}

// Fill rgb image:
rgb_image_->points.clear(); // clear RGB pointcloud
extractRGBFromPointCloud(cloud_, rgb_image_); // fill RGB pointcloud
Expand Down
6 changes: 5 additions & 1 deletion test/test_people_groundBasedPeopleDetectionApp.cpp
Expand Up @@ -60,6 +60,8 @@ PointCloudT::Ptr cloud;
pcl::people::PersonClassifier<pcl::RGB> person_classifier;
std::string svm_filename;
float min_confidence;
float min_width;
float max_width;
float min_height;
float max_height;
float voxel_size;
Expand All @@ -79,7 +81,7 @@ TEST (PCL, GroundBasedPeopleDetectionApp)
people_detector.setVoxelSize(voxel_size); // set the voxel size
people_detector.setIntrinsics(rgb_intrinsics_matrix); // set RGB camera intrinsic parameters
people_detector.setClassifier(person_classifier); // set person classifier
people_detector.setHeightLimits(min_height, max_height); // set person classifier
people_detector.setPersonClusterLimits(min_height, max_height, min_width, max_width);

// Perform people detection on the new cloud:
std::vector<pcl::people::PersonCluster<PointT> > clusters; // vector containing persons clusters
Expand Down Expand Up @@ -120,6 +122,8 @@ int main (int argc, char** argv)
// Algorithm parameters:
svm_filename = argv[1];
min_confidence = -1.5;
min_width = 0.1;
max_width = 8.0;
min_height = 1.3;
max_height = 2.3;
voxel_size = 0.06;
Expand Down

0 comments on commit ba2f4ca

Please sign in to comment.