KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
psi_face_util.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Jinyan Guan
17  * =========================================================================== */
18 
19 /* $Id: psi_face_util.h 18278 2014-11-25 01:42:10Z ksimek $ */
20 
21 #ifndef PSI_FACE_UTIL_H
22 #define PSI_FACE_UTIL_H
23 
24 #include <i_cpp/i_image.h>
25 #include <m_cpp/m_matrix.h>
26 #include <m_cpp/m_vector.h>
31 //#include <psi_cpp/psi_skeleton_trajectory.h>
33 #include <detector_cpp/d_facecom.h>
34 
35 namespace kjb
36 {
37 namespace psi
38 {
39 
40 //typedef Axis_aligned_rectangle_2d Bbox;
41 
46 (
47  const Bbox& face_box,
48  bool standardized = true
49 );
50 
56 (
57  double height,
58  double radius,
59  const Vector& location,
60  double pitch,
61  double yaw,
62  double roll,
63  const Perspective_camera& camera
64 );
65 
70 inline
72 (
73  double cone_length,
74  const Bbox& part_box,
75  const Perspective_camera& camera
76 )
77 {
78  Matrix m(5, 3);
79  const Vector& center = part_box.get_center();
80  double width = part_box.get_width();
81  double height = part_box.get_height();
82  const Matrix& camera_matrix = camera.build_camera_matrix();
83  const Vector& camera_location = geometry::projective_to_euclidean(camera.get_camera_centre());
84 
85  Vector v1(center);
86  Vector v2(center);
87  Vector v3(center);
88  Vector v4(center);
89 
90  // Assuming that the part_box is already standardized
91  v1(0) = v1(0) - width/2.0;
92  v1(1) = v1(1) - height/2.0; // bottom left point
93  v2(0) = v2(0) - width/2.0;
94  v2(1) = v2(1) + height/2.0; // up left point
95  v3(0) = v3(0) + width/2.0;
96  v3(1) = v3(1) + height/2.0; // up right point
97  v4(0) = v4(0) + width/2.0;
98  v4(1) = v4(1) - height/2.0; // bottom right point
99 
100  // get the homogeneous coordinate
105 
106  Vector v1p = backproject(v1, camera_matrix);
107  Vector v2p = backproject(v2, camera_matrix);
108  Vector v3p = backproject(v3, camera_matrix);
109  Vector v4p = backproject(v4, camera_matrix);
110 
111  Vector v1l = camera_location + v1p*cone_length;
112  Vector v2l = camera_location + v2p*cone_length;
113  Vector v3l = camera_location + v3p*cone_length;
114  Vector v4l = camera_location + v4p*cone_length;
115 
116  m.set_row(0, v1l);
117  m.set_row(1, v2l);
118  m.set_row(2, v3l);
119  m.set_row(3, v4l);
120  m.set_row(4, camera_location);
121  return m;
122 }
123 
128 (
129  double radius,
130  double height,
131  const Vector& location
132 );
133 
138 (
139  const Bbox& face_box,
140  const pt::Box_trajectory_map& trajectories,
141  pt::Entity_id& entity_id,
142  size_t index,
143  double overlapping_threshold = 0.4
144 );
145 
150 (
151  const Bbox& face_box,
152  Bbox& corr_body_box,
153  const std::vector<Bbox>& body_boxes,
154  double overlapping_threshold = 0.4
155 );
156 
157 //bool get_holding_object_entity
158 //(
159 // const Bbox& object_box,
160 // const Skeleton_trajectory_map& trajectories,
161 // pt::Entity_id& entity_id,
162 // size_t index,
163 // double overlapping_threshold = 0.1
164 //);
165 
170 (
171  const std::vector<Face_detection> & faces,
172  const Bbox& body_box,
173  Face_detection& matched_face,
174  double overlapping_threshold = 0.4
175 );
176 
183 (
184  const Face_detection& face,
185  const Bbox& body_box,
186  double face_area_threshold = 0.7,
187  double body_area_threshold = 0.07
188 );
189 
195 (
196  std::vector<Face_detection>& faces,
197  double image_width,
198  double image_height
199 );
200 
204 void draw_hull
205 (
206  const Matrix& hull_pts,
207  const Matrix& camera_matrix,
208  double win_width,
209  double win_height,
210  Image& image,
211  const Image::Pixel_type& vertex_pix,
212  const Image::Pixel_type& facet_pix
213 );
214 
218 inline
220 (
221  const Face_detection& fd,
222  Image& img,
223  Image::Pixel_type pixel,
224  int line_width
225 )
226 {
227  double win_width = img.get_num_cols();
228  double win_height = img.get_num_rows();
229  Bbox box(fd.box());
230  pt::unstandardize(box, win_width, win_height);
231  box.draw(img, pixel.r, pixel.g, pixel.b, line_width);
232 }
233 
234 } //namespace psi
235 } //namespace kjb
236 
237 #endif
double get_width() const
returns the width of this bounding box
Definition: gr_2D_bounding_box.h:86
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Class that represents an axis-aligned 2D rectangle. It is defined in terms of its (2D) center...
Definition: gr_2D_bounding_box.h:51
void draw_standardized_face_box(const Face_detection &fd, Image &img, Image::Pixel_type pixel, int line_width)
Definition: psi_face_util.h:220
bool get_corresponding_face(const std::vector< Face_detection > &faces, const Bbox &body_box, Face_detection &matched_face, double overlapping_threshold=0.4)
Get the corresponding face based on the location of the body box.
Definition: psi_face_util.cpp:213
bool face_inside_body_box(const Face_detection &face, const Bbox &body_box, double face_area_threshold=0.7, double body_area_threshold=0.07)
Check if the face box belongs to the body bounding box Note: the Face_detection face_box is in image ...
Definition: psi_face_util.cpp:292
Matrix create_body_part_cone_pts(double cone_length, const Bbox &part_box, const Perspective_camera &camera)
Create a cone for the body parts specified by the body_box and the direction of the tip is specified ...
Definition: psi_face_util.h:72
double get_height() const
returns the height of this bounding box
Definition: gr_2D_bounding_box.h:92
Vector3 backproject(const Vector3 &homo_screen_coord, const Matrix_d< 3, 4 > &camera_matrix)
Same as backproject(), but using Vector3.
Definition: g_camera.cpp:57
height
Definition: APPgetLargeConnectedEdges.m:33
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
kjb_c::Pixel Pixel_type
Definition: i_image.h:80
void set_row(int row, const Generic_vector &v)
Replace a row of the matrix with the given vector.
Definition: m_matrix.h:1682
Vector euclidean_to_projective_2d(const Vector &v)
Converts coordinates in (2D) euclidean space to coordinates in (2D) projective space.
Definition: g_util.cpp:135
Definition: d_facecom.h:38
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Entity + index; used for file I/O.
Definition: tracking_entity.h:82
bool get_corresponding_body_box(const Bbox &face_box, Bbox &corr_body_box, const std::vector< Bbox > &body_boxes, double overlapping_threshold=0.4)
Find the corresponding person box based on the location of the face.
Definition: psi_face_util.cpp:178
Definition: perspective_camera.h:93
int get_num_rows() const
Return the number of rows in the image.
Definition: i_image.h:256
const Vector & get_center() const
returns the center of this Axis_aligned_rectangle_2d
Definition: gr_2D_bounding_box.h:80
const Bbox & box() const
DOCUMENT LATER!
Definition: d_facecom.h:56
const kjb::Vector & get_camera_centre() const
returns the camera centre
Definition: perspective_camera.h:194
Represents a set of trajectories; it is a map from entity to trajectory.
Definition: tracking_trajectory.h:53
bool get_corresponding_entity(const Bbox &face_box, const pt::Box_trajectory_map &trajectories, pt::Entity_id &entity_id, size_t index, double overlapping_threshold=0.4)
Get the corresponding person based on the location of the face.
Definition: psi_face_util.cpp:141
int get_num_cols() const
Return the number of columns in the image.
Definition: i_image.h:262
void standardize_face_boxes(std::vector< Face_detection > &faces, double image_width, double image_height)
Standardize face boxes.
Definition: psi_face_util.cpp:323
Bbox estimate_body_box(const Bbox &face_box, bool standardized=true)
Create a body bounding box based on the detected face box.
Definition: psi_face_util.cpp:38
void unstandardize(Vector &v, double cam_width, double cam_height)
Changes vector to unstandard (image) coordinate system.
Definition: pt_util.h:83
Class representing an axis-aligned, 2D rectangle.
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Matrix create_gaze_cone_pts(double height, double radius, const Vector &location, double pitch, double yaw, double roll, const Perspective_camera &camera)
Create a cone whose tip is at the location, and the direction of the tip is specified by directio...
Definition: psi_face_util.cpp:64
Code for a wrapper class around the C struct KJB_Image.
for m
Definition: APPgetLargeConnectedEdges.m:64
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
const Matrix & build_camera_matrix() const
Definition: perspective_camera.h:487
void draw_hull(const Matrix &hull_pts, const Matrix &camera_matrix, double win_width, double win_height, Image &image, const Image::Pixel_type &vertex_pix, const Image::Pixel_type &facet_pix)
Draw hull for debugging purposes.
Definition: psi_face_util.cpp:338
Vector projective_to_euclidean(const Vector &v)
Converts coordinates in projective space to coordinates in euclidean space.
Definition: g_util.cpp:96
Axis_aligned_rectangle_2d Bbox
Definition: psi_deva_skeleton.h:32
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Matrix create_cylinder_pts(double radius, double height, const Vector &location)
Create a cylinder for the body and return the points on the cylinder.
Definition: psi_face_util.cpp:112