69 for (
int i =
list_.size(); i > 0; i--)
84 double face_size_max_m,
double max_face_z_m,
double face_sep_dist_m)
94 bool cascade_ok =
cascade_.load(haar_classifier_filename);
98 ROS_ERROR_STREAM(
"Cascade file " << haar_classifier_filename <<
" doesn't exist.");
106 const cv::Mat &disparity_image,
112 if (image.channels() == 1)
117 else if (image.channels() == 3)
124 std::cerr <<
"Unknown image type" << std::endl;
154 boost::mutex::scoped_lock tlock(
t_mutex_, boost::defer_lock);
173 int this_min_face_size =
static_cast<int>(floor(fabs(p2_2.x - p2_1.x)));
175 std::vector<cv::Rect> faces_vec;
177 cv::Size(this_min_face_size, this_min_face_size));
181 cv::Scalar color(0, 255, 0);
183 double avg_disp = 0.0;
184 cv::Mat uvd(1, 3, CV_32FC1);
185 cv::Mat xyz(1, 3, CV_32FC1);
187 for (uint iface = 0; iface < faces_vec.size(); iface++)
191 one_face.
box2d = faces_vec[iface];
196 cv::Rect(floor(one_face.
box2d.x + 0.25 * one_face.
box2d.width),
197 floor(one_face.
box2d.y + 0.25 * one_face.
box2d.height),
198 floor(one_face.
box2d.x + 0.75 * one_face.
box2d.width) -
199 floor(one_face.
box2d.x + 0.25 * one_face.
box2d.width) + 1,
200 floor(one_face.
box2d.y + 0.75 * one_face.
box2d.height) -
201 floor(one_face.
box2d.y + 0.25 * one_face.
box2d.height) + 1));
202 cv::Mat disp_roi = disp_roi_shallow.clone();
203 cv::Mat tmat = disp_roi.reshape(1, disp_roi.rows * disp_roi.cols);
205 cv::sort(tmat, tmat_sorted, CV_SORT_EVERY_COLUMN + CV_SORT_DESCENDING);
208 avg_disp = tmat_sorted.at<
float>(floor(cv::countNonZero(tmat_sorted >= 0.0) / 2.0));
212 one_face.
box2d.y + one_face.
box2d.height / 2.0);
222 one_face.
width3d = fabs(p3_2.x - p3_1.x);
234 one_face.
center3d = cv::Point3d(0.0, 0.0, 0.0);
235 one_face.
status =
"unknown";
241 faces_.push_back(one_face);
254 double face_size_max_m,
double max_face_z_m,
double face_sep_dist_m)
264 bool cascade_ok =
cascade_.load(haar_classifier_filename);
268 ROS_ERROR_STREAM(
"Cascade file " << haar_classifier_filename <<
" doesn't exist.");
282 if (image.channels() == 1)
287 else if (image.channels() == 3)
294 std::cerr <<
"Unknown image type" << std::endl;
324 boost::mutex::scoped_lock tlock(
t_mutex_, boost::defer_lock);
343 int this_min_face_size =
static_cast<int>(floor(fabs(p2_2.x - p2_1.x)));
345 std::vector<cv::Rect> faces_vec;
347 cv::Size(this_min_face_size, this_min_face_size));
351 cv::Scalar color(0, 255, 0);
354 cv::Mat uvd(1, 3, CV_32FC1);
355 cv::Mat xyz(1, 3, CV_32FC1);
357 for (uint iface = 0; iface < faces_vec.size(); iface++)
361 one_face.
box2d = faces_vec[iface];
366 cv::Rect(floor(one_face.
box2d.x + 0.25 * one_face.
box2d.width),
367 floor(one_face.
box2d.y + 0.25 * one_face.
box2d.height),
368 floor(one_face.
box2d.x + 0.75 * one_face.
box2d.width) -
369 floor(one_face.
box2d.x + 0.25 * one_face.
box2d.width) + 1,
370 floor(one_face.
box2d.y + 0.75 * one_face.
box2d.height) -
371 floor(one_face.
box2d.y + 0.25 * one_face.
box2d.height) + 1));
375 one_face.
box2d.y + one_face.
box2d.height / 2.0);
382 std::vector<float> depths;
384 for (
int i = 0; i < depth_roi_shallow.rows; i++)
386 const float* dptr = depth_roi_shallow.ptr<
float>(i);
387 for (
int j = 0; j < depth_roi_shallow.cols; j++)
389 if (dptr[j] == dptr[j])
391 depths.push_back(dptr[j]);
396 std::vector<float>::iterator dbegin = depths.begin();
397 std::vector<float>::iterator dend = depths.end();
399 if (depths.size() > 0)
401 std::sort(dbegin, dend);
402 avg_d = depths[floor(depths.size() / 2.0)];
418 one_face.
center3d = cv::Point3d(0.0, 0.0, 0.0);
419 one_face.
status =
"unknown";
425 faces_.push_back(one_face);
void initFaceDetectionDepth(uint num_cascades, std::string haar_classifier_filename, double face_size_min_m, double face_size_max_m, double max_face_z_m, double face_sep_dist_m)
Initialize the face detector with images and depth.
std::vector< Face > list_
boost::condition face_detection_ready_cond_
A structure for holding information about boxes in 2d and 3d.
std::vector< Box2D3D > detectAllFacesDepth(const cv::Mat &image, double threshold, const cv::Mat &depth_image, image_geometry::StereoCameraModel *cam_model)
Detect all faces in an image and depth image.
int num_threads_to_wait_for_
std::vector< Box2D3D > faces_
const PinholeCameraModel & left() const
cv::Mat const * disparity_image_
cv::Mat const * depth_image_
image_geometry::StereoCameraModel * cam_model_
void projectDisparityTo3d(const cv::Point2d &left_uv_rect, float disparity, cv::Point3d &xyz) const
boost::thread_group threads_
void faceDetectionThreadDepth(uint i)
boost::condition face_detection_done_cond_
void faceDetectionThreadDisparity(uint i)
boost::mutex * face_go_mutex_
void initFaceDetectionDisparity(uint num_cascades, std::string haar_classifier_filename, double face_size_min_m, double face_size_max_m, double max_face_z_m, double face_sep_dist_m)
Initialize the face detector with images and disparities.
boost::mutex face_done_mutex_
#define ROS_ERROR_STREAM(args)
cv::CascadeClassifier cascade_
std::vector< Box2D3D > detectAllFacesDisparity(const cv::Mat &image, double threshold, const cv::Mat &disparity_image, image_geometry::StereoCameraModel *cam_model)
Detect all faces in an image and disparity image.