KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pt_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: Kyle Simek, Ernesto Brau, Jinyan Guan
17  * =========================================================================== */
18 
19 /* $Id: pt_util.h 18839 2015-04-12 22:22:18Z jguan1 $ */
20 
21 #ifndef PT_UTIL
22 #define PT_UTIL
23 
24 #include <m_cpp/m_vector.h>
35 #include <detector_cpp/d_bbox.h>
38 #include <boost/optional.hpp>
39 
40 namespace kjb {
41 namespace pt {
42 
46 inline
47 void standardize(Vector& v, double cam_width, double cam_height)
48 {
49  Vector t(-cam_width/2.0, -cam_height/2.0);
50  v += t;
51  v[1] = -v[1];
52 }
53 
57 inline
58 void standardize(Bbox& box, double cam_width, double cam_height)
59 {
60  Vector t(-cam_width/2.0, -cam_height/2.0);
61 
62  // will flip y-axis
63  Vector s(1.0, -1.0);
64 
65  translate(box, t);
66  scale(box, s);
67 }
68 
72 void standardize
73 (
74  Deva_facemark& face,
75  double cam_width,
76  double cam_height
77 );
78 
82 inline
83 void unstandardize(Vector& v, double cam_width, double cam_height)
84 {
85  Vector t(cam_width/2.0, cam_height/2.0);
86  v[1] = -v[1];
87  v += t;
88 }
89 
93 inline
94 void unstandardize(Bbox& box, double cam_width, double cam_height)
95 {
96  Vector t(cam_width/2.0, cam_height/2.0);
97 
98  // will flip y-axis
99  Vector s(1.0, -1.0);
100  scale(box, s);
101  translate(box, t);
102 }
103 
107 void unstandardize
108 (
109  Deva_facemark& face,
110  double cam_width,
111  double cam_height
112 );
113 
117 void standardize
118 (
119  Deva_facemark& face,
120  double cam_width,
121  double cam_height
122 );
123 
129 (
130  const Box_data& data,
131  const Box_trajectory_map& gt_btrajs,
132  double width,
133  double height,
134  boost::optional<const Perspective_camera&> cam_p = boost::none,
135  boost::optional<const Facemark_data&> fm_data_p = boost::none
136 );
137 
142 Box_data make_gt_data
143 (
144  const Box_trajectory_map& gt_btrajs,
145  double width,
146  double height
147 );
148 
153 {
154  double x;
155  double y_bottom;
157  int origin_frame; // + foward, - backward
158 };
159 
164 {
165  inline bool operator()
166  (
167  const Propagated_2d_info& p1,
168  const Propagated_2d_info& p2
169  ) const
170  {
171  return p1.y_bottom < p2.y_bottom;
172  }
173 };
174 
179 std::map<int, std::vector<Propagated_2d_info> > propagate_boxes_by_flow
180 (
181  const Target& target,
182  const std::vector<Integral_flow>& x_flows,
183  const std::vector<Integral_flow>& y_flows,
184  const std::vector<Integral_flow>& back_x_flows,
185  const std::vector<Integral_flow>& back_y_flows,
186  size_t duration
187 );
188 
195 inline
196 double chi_squared_dist_to_prob(double chi_square_dist)
197 {
198  return 1.0/(1.0 + exp(-(3.50281 + chi_square_dist * (-64.49790))));
199 }
200 
204 typedef std::map<const Detection_box*, Matrix> Hist_map;
206 {
207 public:
209  (
210  const std::vector<Hist_map>& hist,
211  const std::vector<Integral_flow>& flows_x,
212  const std::vector<Integral_flow>& flows_y
213  ) : m_hists(hist),
214  m_flows_x(flows_x),
215  m_flows_y(flows_y)
216  {}
217 
218  std::vector<double> operator()
219  (
220  const Target* target_p,
221  int t1,
222  const Detection_box* candidate_p,
223  int t2,
224  size_t wsz = 1
225  ) const;
226 
227 private:
228  const std::vector<Hist_map>& m_hists;
229  const std::vector<Integral_flow>& m_flows_x;
230  const std::vector<Integral_flow>& m_flows_y;
231 };
232 
239 (
240  const Integral_flow& fx,
241  const Integral_flow& fy,
242  const Bbox& box,
243  const Visibility& vis
244 );
245 
249 void prune_by_height
250 (
251  std::vector<Deva_detection>& deva_boxes,
252  double image_width,
253  double image_height,
254  const Perspective_camera& camera,
255  double average_height
256 );
257 
259 inline
261 {
262  Vector temp = x;
263  temp.resize(4, 1.0);
265 }
266 
271 void update_facemarks(const Ascn& ascn, const Facemark_data& fms);
272 
277 //void update_facemarks(const Scene& scene, const Facemark_data& fms);
278 
282 void clear_facemarks(const Ascn& ascn);
283 
284 }} // namespace kjb::pt
285 
286 #endif /*PT_UTIL */
287 
Vector & resize(int new_length, Value_type pad=Value_type(0))
Resize vector, retaining previous values.
Definition: m_vector.cpp:242
Class that represents a detection bounding box from any source.
Definition: pt_detection_box.h:42
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 update_facemarks(const Ascn &ascn, const Facemark_data &fms)
Update facemark detections for face trajectories.
Definition: pt_util.cpp:721
void translate(kjb::Axis_aligned_rectangle_2d &box, const kjb::Vector &t)
Definition: gr_2D_bounding_box.h:258
Generic_trajectory_map< Bbox > Box_trajectory_map
Definition: pt_box_trajectory.h:44
double x
Definition: pt_util.h:154
Definition: d_deva_facemark.h:34
mcmcda::Association< Target > Ascn
Definition: pt_association.h:30
height
Definition: APPgetLargeConnectedEdges.m:33
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Bbox box
Definition: pt_util.h:156
Vector average_box_flow(const Integral_flow &fx, const Integral_flow &fy, const Bbox &box, const Visibility &vis)
Compute the average flow in a box, ignoring occluded parts.
Definition: pt_util.cpp:632
double chi_squared_dist_to_prob(double chi_square_dist)
Given the chi-square distance between the histograms of two detection boxes.
Definition: pt_util.h:196
double y_bottom
Definition: pt_util.h:155
Vector projective_to_euclidean_2d(const Vector &v)
Converts coordinates in (2D) projective space to coordinates in (2D) euclidean space.
Definition: g_util.cpp:109
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
std::vector< std::vector< Deva_facemark > > Facemark_data
Definition: pt_data.h:129
std::map< const Detection_box *, Matrix > Hist_map
Scores based on histogram.
Definition: pt_util.h:204
Box_data make_gt_data(const Box_trajectory_map &gt_btrajs, double width, double height)
Create data from GT box trajectories and compute association based upon it.
Definition: pt_util.cpp:325
Definition: perspective_camera.h:93
x
Definition: APPgetLargeConnectedEdges.m:100
Class that represents a target moving through space.
Definition: pt_target.h:50
int origin_frame
Definition: pt_util.h:157
Propagated 2D information using optical flow.
Definition: pt_util.h:152
void clear_facemarks(const Ascn &ascn)
Update facemark detections for face trajectories.
Definition: pt_util.cpp:810
Definition: pt_util.h:205
Vector project_point(const Perspective_camera &cam, const Vector &x)
Projects a 3D point into a 2D point using camera.
Definition: pt_util.h:260
Comparator for Propagated_2d_info.
Definition: pt_util.h:163
std::map< int, std::vector< Propagated_2d_info > > propagate_boxes_by_flow(const Target &target, const std::vector< Integral_flow > &x_flows, const std::vector< Integral_flow > &y_flows, const std::vector< Integral_flow > &back_x_flows, const std::vector< Integral_flow > &back_y_flows, size_t duration)
Propagate the detection boxes based on optical flow to neighboring frames.
Definition: pt_util.cpp:353
Definition: flow_integral_flow.h:38
Feature_score(const std::vector< Hist_map > &hist, const std::vector< Integral_flow > &flows_x, const std::vector< Integral_flow > &flows_y)
Definition: pt_util.h:209
void unstandardize(Vector &v, double cam_width, double cam_height)
Changes vector to unstandard (image) coordinate system.
Definition: pt_util.h:83
Ascn make_gt_association(const Box_data &data, const Box_trajectory_map &gt_btrajs, double width, double height, boost::optional< const Perspective_camera & > cam_p=boost::none, boost::optional< const Facemark_data & > fm_data_p=boost::none)
Create data from GT box trajectories and compute association based upon it.
Definition: pt_util.cpp:205
Class representing an axis-aligned, 2D rectangle.
const Matrix & get_camera_matrix() const
Definition: perspective_camera.h:473
void standardize(Vector &v, double cam_width, double cam_height)
Changes Vector to standard (camera) coordinate system.
Definition: pt_util.h:47
void prune_by_height(std::vector< Deva_detection > &deva_boxes, double image_width, double image_height, const Perspective_camera &camera, double average_height)
Prune the deva boxes based on the average entity height.
Definition: pt_util.cpp:680
void scale(kjb::Axis_aligned_rectangle_2d &box, const kjb::Vector &s)
Definition: gr_2D_bounding_box.cpp:108
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...