KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
st_manhattan_hog.h
Go to the documentation of this file.
1 /* $Id: edge.h 13438 2012-12-10 18:27:38Z predoehl $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== */
19 
20 #ifndef KJB_CPP_EDGE_MANHATTAN_HOG_H
21 #define KJB_CPP_EDGE_MANHATTAN_HOG_H
22 
23 #include <string>
24 
25 #include <edge_cpp/hog.h>
26 #include "st_cpp/st_parapiped.h"
28 #include "edge_cpp/line_segment.h"
29 
30 namespace kjb
31 {
32 
33 void compute_HOG_features(const Image & img, int bin_size);
34 
35 class Manhattan_hog: public Readable, public Writeable
36 {
37 public:
39  (
40  const Hog_responses & hog_responses,
41  const Image & image,
42  const Perspective_camera & camera,
43  const Parametric_parapiped & parapiped
44  );
45 
46  Manhattan_hog(const std::string & file_name)
47  {
48  Readable::read(file_name.c_str());
49  }
50 
51  Manhattan_hog(const Manhattan_hog & src) : Readable(src), Writeable(src), manhattan_hog_size(src.manhattan_hog_size)
52  {
53  hog_responses_horizontal = new float[manhattan_hog_size];
54  memcpy(hog_responses_horizontal, src.hog_responses_horizontal, manhattan_hog_size*sizeof(float));
55  hog_responses_vertical_1 = new float[manhattan_hog_size];
56  memcpy(hog_responses_vertical_1, src.hog_responses_vertical_1, manhattan_hog_size*sizeof(float));
57  hog_responses_vertical_2 = new float[manhattan_hog_size];
58  memcpy(hog_responses_vertical_2, src.hog_responses_vertical_2, manhattan_hog_size*sizeof(float));
59  num_hog_cols = src.num_hog_cols;
60  num_hog_rows = src.num_hog_rows;
61  hog_maxs = src.hog_maxs;
62  bin_size = src.bin_size;
63  }
64 
66  {
67  delete[] hog_responses_horizontal;
68  delete[] hog_responses_vertical_1;
69  delete[] hog_responses_vertical_2;
70  }
71 
73  {
74  delete[] hog_responses_horizontal;
75  delete[] hog_responses_vertical_1;
76  delete[] hog_responses_vertical_2;
77  hog_responses_horizontal = NULL;
78  hog_responses_vertical_1 = NULL;
79  hog_responses_vertical_2 = NULL;
80  hog_responses_horizontal = new float[manhattan_hog_size];
81  memcpy(hog_responses_horizontal, src.hog_responses_horizontal, manhattan_hog_size*sizeof(float));
82  hog_responses_vertical_1 = new float[manhattan_hog_size];
83  memcpy(hog_responses_vertical_1, src.hog_responses_vertical_1, manhattan_hog_size*sizeof(float));
84  hog_responses_vertical_2 = new float[manhattan_hog_size];
85  memcpy(hog_responses_vertical_2, src.hog_responses_vertical_2, manhattan_hog_size*sizeof(float));
86  num_hog_cols = src.num_hog_cols;
87  num_hog_rows = src.num_hog_rows;
88  hog_maxs = src.hog_maxs;
89  bin_size = src.bin_size;
90  return (*this);
91  }
92 
94  void read(std::istream& in);
95 
97  void write(std::ostream& out) const;
98 
99  int compute_manhattan_hog_size(int hog_size_2D)
100  {
101  return (hog_size_2D/32)*27;
102  }
103 
105  (
106  std::vector<kjb::Vector> & manhattan_dir_3d_vertical,
107  std::vector<kjb::Vector> & manhattan_dir_3d_vertical1,
108  std::vector<kjb::Vector> & manhattan_dir_3d_vertical2,
109  int num_directions
110  ) const;
111 
113  (
114  const std::vector<kjb::Vector> & manhattan_dir_3d_vertical,
115  const std::vector<kjb::Vector> & manhattan_dir_3d_vertical1,
116  const std::vector<kjb::Vector> & manhattan_dir_3d_vertical2,
117  const kjb::Vector & center_in_pp_coordinates,
118  const kjb::Parametric_parapiped & pp,
119  const kjb::Perspective_camera & camera,
120  int img_height,
121  std::vector<kjb::Vector> & projected_manhattan_dir_horizontal,
122  std::vector<kjb::Vector> & projected_manhattan_dir_vertical1,
123  std::vector<kjb::Vector> & projected_manhattan_dir_vertical2
124  ) const;
125 
127  (
128  const std::vector<kjb::Vector> & projected_directions,
129  const float * weights_2D,
130  float * weights_3D,
131  double angle_increment,
132  int inum_bins
133  );
134 
136  (
137  std::vector<Line_segment> & line_segments,
138  const std::vector<kjb::Vector> & projected_directions,
139  double center_x,
140  double center_y,
141  double length
142  ) const;
143 
145  (
146  const Hog_responses & hog_responses,
147  const Image & image,
148  const Perspective_camera & camera,
149  const Parametric_parapiped & parapiped
150  ) const;
151 
152  void get_hog_pixels(std::vector<std::pair<int, int> > & hog_pixels) const;
153 
154  void get_hog_offsets(std::vector<int>& hog_offsets) const;
155 
156  inline int get_hog_cell_x_center(int hog_x_index) const
157  {
158  return 1.5 + bin_size + (bin_size*hog_x_index);
159  }
160 
161  inline int get_hog_cell_y_center(int hog_y_index) const
162  {
163  return 1.5 + bin_size + (bin_size*hog_y_index);
164  }
165 
166  inline const float * get_horizontal() const
167  {
168  return hog_responses_horizontal;
169  }
170 
171  inline const float * get_vertical1() const
172  {
173  return hog_responses_vertical_1;
174  }
175 
176  inline const float * get_vertical2() const
177  {
178  return hog_responses_vertical_2;
179  }
180 
181  inline const Vector & get_hog_maxs() const
182  {
183  return hog_maxs;
184  }
185 
186  inline int get_num_hog_rows() const
187  {
188  return num_hog_rows;
189  }
190 
191  inline int get_num_hog_cols() const
192  {
193  return num_hog_cols;
194  }
195 
196 private:
197  int manhattan_hog_size;
198  int num_hog_rows;
199  int num_hog_cols;
200  float * hog_responses_horizontal;
201  float * hog_responses_vertical_1;
202  float * hog_responses_vertical_2;
203  Vector hog_maxs;
204  int bin_size;
205 
206  void find_2D_hog_directions(std::vector<kjb::Vector> & directions_2D, int num_angle_bins) const;
207 
208  double find_2D_weight_by_interpolation
209  (
210  const Vector & idirection,
211  double angle_increment,
212  int inum_bins,
213  const float * weights
214  ) const;
215 };
216 
217 } // namespace kjb
218 #endif
int get_num_hog_cols() const
Definition: st_manhattan_hog.h:191
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
Image draw_image_with_vertical_segments(const Hog_responses &hog_responses, const Image &image, const Perspective_camera &camera, const Parametric_parapiped &parapiped) const
Definition: st_manhattan_hog.cpp:354
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
const float * get_vertical1() const
Definition: st_manhattan_hog.h:171
int get_hog_cell_x_center(int hog_x_index) const
Definition: st_manhattan_hog.h:156
void write(std::ostream &out) const
Writes this Line segment to an output stream.
Definition: st_manhattan_hog.cpp:139
void compute_HOG_features(const Image &img, int bin_size)
Definition: st_manhattan_hog.h:35
void read(std::istream &in)
Reads this Line segment from an input stream.
Definition: st_manhattan_hog.cpp:107
void get_projected_manhattan_directions(const std::vector< kjb::Vector > &manhattan_dir_3d_vertical, const std::vector< kjb::Vector > &manhattan_dir_3d_vertical1, const std::vector< kjb::Vector > &manhattan_dir_3d_vertical2, const kjb::Vector &center_in_pp_coordinates, const kjb::Parametric_parapiped &pp, const kjb::Perspective_camera &camera, int img_height, std::vector< kjb::Vector > &projected_manhattan_dir_horizontal, std::vector< kjb::Vector > &projected_manhattan_dir_vertical1, std::vector< kjb::Vector > &projected_manhattan_dir_vertical2) const
Definition: st_manhattan_hog.cpp:247
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
void interpolate_projected_directions(const std::vector< kjb::Vector > &projected_directions, const float *weights_2D, float *weights_3D, double angle_increment, int inum_bins)
Definition: st_manhattan_hog.cpp:309
size_t length(const C &cner)
Counts the total number of elements in a 2D STL-style container.
Definition: l_util.h:17
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
int compute_manhattan_hog_size(int hog_size_2D)
Definition: st_manhattan_hog.h:99
int get_num_hog_rows() const
Definition: st_manhattan_hog.h:186
Definition: perspective_camera.h:93
int get_hog_cell_y_center(int hog_y_index) const
Definition: st_manhattan_hog.h:161
void get_3D_manhattan_directions(std::vector< kjb::Vector > &manhattan_dir_3d_vertical, std::vector< kjb::Vector > &manhattan_dir_3d_vertical1, std::vector< kjb::Vector > &manhattan_dir_3d_vertical2, int num_directions) const
Definition: st_manhattan_hog.cpp:198
Manhattan_hog(const Hog_responses &hog_responses, const Image &image, const Perspective_camera &camera, const Parametric_parapiped &parapiped)
Definition: st_manhattan_hog.cpp:23
void get_line_segments_for_drawing(std::vector< Line_segment > &line_segments, const std::vector< kjb::Vector > &projected_directions, double center_x, double center_y, double length) const
Definition: st_manhattan_hog.cpp:325
void get_hog_offsets(std::vector< int > &hog_offsets) const
Definition: st_manhattan_hog.cpp:501
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
const Vector & get_hog_maxs() const
Definition: st_manhattan_hog.h:181
Definition: hog.h:45
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
Manhattan_hog(const std::string &file_name)
Definition: st_manhattan_hog.h:46
~Manhattan_hog()
Definition: st_manhattan_hog.h:65
Manhattan_hog & operator=(const Manhattan_hog &src)
Definition: st_manhattan_hog.h:72
Manhattan_hog(const Manhattan_hog &src)
Definition: st_manhattan_hog.h:51
const float * get_horizontal() const
Definition: st_manhattan_hog.h:166
void get_hog_pixels(std::vector< std::pair< int, int > > &hog_pixels) const
Definition: st_manhattan_hog.cpp:489
const float * get_vertical2() const
Definition: st_manhattan_hog.h:176
Definition: st_parapiped.h:99