KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flow_feature_set.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: flow_feature_set.h 18278 2014-11-25 01:42:10Z ksimek $ */
20 
21 #ifndef KJB_FLOW_FEATURE_SET_H
22 #define KJB_FLOW_FEATURE_SET_H
23 
24 #include <m_cpp/m_vector.h>
26 
27 #include <set>
28 #include <vector>
29 #include <string>
30 #include <utility>
31 #include <numeric>
32 
33 
34 namespace kjb {
35 
38 
39 typedef std::pair<float, float> Feature;
40 typedef std::pair<Vector, Vector> Feature_pair;
41 
44 {
46  bool operator()
47  (
48  const Feature_pair& feature_pair_1,
49  const Feature_pair& feature_pair_2
50  ) const
51  {
52  return feature_pair_1.first < feature_pair_2.first;
53  }
54 };
55 
56 typedef std::set<Feature_pair, Compare_flow_features> Flow_feature_set;
57 
62 (
63  const std::string& fname
64 );
65 
70 std::vector<Feature_pair> look_up_features
71 (
72  const Flow_feature_set& of_set,
73  const Axis_aligned_rectangle_2d& box
74 );
75 
80 std::vector<Feature_pair> look_up_bg_features
81 (
82  const Flow_feature_set& of_set,
83  const std::vector<Axis_aligned_rectangle_2d>& model_boxes
84 );
85 
90 inline
92 (
93  const std::vector<Vector>& flows
94 )
95 {
96  Vector ave_flow(2, 0.0);
97  Vector total_flow = std::accumulate(flows.begin(), flows.end(), ave_flow);
98  if(flows.size() > 0)
99  {
100  ave_flow = total_flow/flows.size();
101  }
102  return ave_flow;
103 }
104 
108 inline
110 (
111  const Vector& f_p,
112  const Vector& f_n
113 )
114 {
115  return f_p.magnitude() > f_n.magnitude();
116 }
117 
119 std::vector<Vector> valid_flow
120 (
121  const std::vector<Feature_pair>& feature_pairs,
122  double percentile = 1.0
123 );
124 
130 std::vector<Vector> valid_flow
131 (
132  const std::vector<Feature_pair>& feature_pairs,
133  const std::vector<size_t>& angle_hist
134 );
135 
137 std::vector<size_t> angle_histogram
138 (
139  const std::vector<Feature_pair>& feature_pairs,
140  size_t num_bins = 36
141 );
142 
148 (
149  const Flow_feature_set& of_set,
150  const Axis_aligned_rectangle_2d& old_model_box,
151  const Vector& old_velocity,
152  MOVE_DIRECTION dir,
153  size_t unit = 1
154 );
155 
161 (
162  const Flow_feature_set& of_set,
163  const Axis_aligned_rectangle_2d& old_box,
164  const Axis_aligned_rectangle_2d& new_box,
165  const Vector& old_velocity
166 );
167 
169 Vector lookup_feature
170 (
171  const Flow_feature_set& of_set,
172  size_t x,
173  size_t y,
174  size_t subsample_sz = 1
175 );
176 
180 Vector total_flow
181 (
182  const Flow_feature_set& of_set,
183  const Axis_aligned_rectangle_2d& box
184  //size_t subsample_sz = 1
185 );
186 
187 } //namespace kjb
188 
189 #endif /* KJB_PSI_OPTICAL_FLOW_H */
190 
std::vector< Feature_pair > look_up_bg_features(const Flow_feature_set &of_set, const std::vector< Axis_aligned_rectangle_2d > &model_boxes)
Given the features and all the model boxes at cur_frame, find all the background features.
Definition: flow_feature_set.cpp:127
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
Class that represents an axis-aligned 2D rectangle. It is defined in terms of its (2D) center...
Definition: gr_2D_bounding_box.h:51
double accumulate(const Matrix_d< R, C, T > &mat, double init)
Definition: m_matrix_d.impl.h:432
Definition: flow_feature_set.h:37
std::vector< size_t > angle_histogram(const std::vector< Feature_pair > &feature_pairs, size_t num_bins=36)
Compute the histogram of the flow vector angles.
Definition: flow_feature_set.cpp:241
Definition: flow_feature_set.h:37
std::set< Feature_pair, Compare_flow_features > Flow_feature_set
Definition: flow_feature_set.h:56
Definition: flow_feature_set.h:37
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
std::vector< Feature_pair > look_up_features(const Flow_feature_set &of_set, const Axis_aligned_rectangle_2d &box)
Given the features and a bounding box at the same frame, find and return the detected features inside...
Definition: flow_feature_set.cpp:80
bool compare_flow_magnitude(const Vector &f_p, const Vector &f_n)
Compare the optical flow magnitude.
Definition: flow_feature_set.h:110
Vector lookup_feature(const Flow_feature_set &of_set, size_t x, size_t y, size_t subsample_sz=1)
Looks up a feature in a feature set; deals with subsampling.
Definition: flow_feature_set.cpp:598
Vector total_flow(const Flow_feature_set &of_set, const Axis_aligned_rectangle_2d &box)
Compute the average flow vector inside the bounding box.
Definition: flow_feature_set.cpp:700
x
Definition: APPgetLargeConnectedEdges.m:100
MOVE_DIRECTION
Move direction of the 2D bounding box.
Definition: flow_feature_set.h:37
Value_type magnitude() const
Return this vector's magnitude.
Definition: m_vector.h:1490
Definition: flow_feature_set.h:37
std::pair< Vector, Vector > Feature_pair
Definition: flow_feature_set.h:40
Vector update_average_velocity(const Flow_feature_set &of_set, const Axis_aligned_rectangle_2d &old_model_box, const Vector &old_velocity, MOVE_DIRECTION dir, size_t unit=1)
Update the average flow velocity based on the moving direction.
Definition: flow_feature_set.cpp:269
Class representing an axis-aligned, 2D rectangle.
std::vector< Vector > valid_flow(const std::vector< Feature_pair > &feature_pairs, double percentile=1.0)
Get valid features.
Definition: flow_feature_set.cpp:172
Functor to compare two Feature_pair.
Definition: flow_feature_set.h:43
Vector average_flow(const Matrix &x_flows, const Matrix &y_flows, const Axis_aligned_rectangle_2d &roi)
Get the average optical flow inside a rectangle region.
Definition: flow_dense.cpp:30
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Flow_feature_set read_flow_features(const std::string &fname)
Read in the procomputed optical flow from files.
Definition: flow_feature_set.cpp:41
std::pair< float, float > Feature
Definition: flow_feature_set.h:39