KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pt_detection_box.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: Ernesto Brau
17  * =========================================================================== */
18 
19 /* $Id: pt_detection_box.h 18278 2014-11-25 01:42:10Z ksimek $ */
20 
21 #ifndef PT_DETECTION_BOX_H
22 #define PT_DETECTION_BOX_H
23 
24 #include <detector_cpp/d_bbox.h>
25 #include <m_cpp/m_vector.h>
28 #include <string>
29 #include <iostream>
30 #include <iomanip>
31 #include <sstream>
32 #include <ios>
33 
34 namespace kjb {
35 namespace pt {
36 
43 {
45  double prob_noise;
46  std::string type;
47 
52  (
53  const Bbox& bb,
54  double pnoise,
55  const std::string& model_type
56  ) :
57  bbox(bb),
58  prob_noise(pnoise),
59  type(model_type)
60  {}
61 
63  friend void swap(Detection_box& b1, Detection_box& b2)
64  {
65  using std::swap;
66  swap(b1.bbox, b2.bbox);
67  swap(b1.prob_noise, b2.prob_noise);
68  swap(b1.type, b2.type);
69  }
70 };
71 
76 inline
77 bool operator<(const Detection_box& b1, const Detection_box& b2)
78 {
80  {
81  return true;
82  }
83 
85  {
86  return false;
87  }
88 
89  return b1.bbox.get_top_center() < b2.bbox.get_top_center();
90 }
91 
93 inline
94 std::ostream& operator<<(std::ostream& ost, const Detection_box& dbox)
95 {
96  std::streamsize w = ost.width();
97  std::streamsize p = ost.precision();
98  std::ios::fmtflags f = ost.flags();
99  ost << std::scientific;
100 
101  ost << dbox.bbox;
102  ost << std::setw(16) << std::setprecision(8) << dbox.prob_noise << " ";
103  ost << dbox.type;
104 
105  ost.width(w);
106  ost.precision(p);
107  ost.flags(f);
108 
109  return ost;
110 }
111 
115 inline
116 Detection_box parse_detection_box(const std::string& line)
117 {
118  using namespace std;
119 
120  istringstream istr(line);
121 
122  Vector center(2);
123  istr >> center[0];
124  istr >> center[1];
125 
126  double width;
127  double height;
128  istr >> width;
129  istr >> height;
130 
131  Bbox box(center, width, height);
132 
133  double prob_noise;
134  istr >> prob_noise;
135 
136  std::string tp;
137  istr >> tp;
138 
139  IFT(istr.eof() || !istr.fail(), IO_error,
140  "Cannot read Detection_box: line has wrong format.");
141 
142  return Detection_box(box, prob_noise, tp);
143 }
144 
148 std::vector<Detection_box> parse_detection_file(const std::string& filename);
149 
154 bool similar_boxes
155 (
156  const Bbox& model_box,
157  const Bbox& data_box,
158  double area_thresh_lower = 0.6,
159  double area_thresh_upper = 1.2
160 );
161 
163 inline
164 bool box_on_ground(const Detection_box& dbox, const Perspective_camera& cam)
165 {
166  Ground_back_projector gbp(cam, 0.0);
167  Vector bbot = dbox.bbox.get_bottom_center();
168  return !gbp(bbot[0], bbot[1]).empty();
169 }
170 
171 }} // namespace kjb::pt
172 
173 #endif /*PT_DETECTION_BOX_H */
174 
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
double prob_noise
Definition: pt_detection_box.h:45
Detection_box(const Bbox &bb, double pnoise, const std::string &model_type)
Create data box from rectangle and 3D ground location.
Definition: pt_detection_box.h:52
Definition: camera_backproject.h:113
friend void swap(Detection_box &b1, Detection_box &b2)
Swap two detection boxes.
Definition: pt_detection_box.h:63
height
Definition: APPgetLargeConnectedEdges.m:33
Vector get_top_center() const
Definition: gr_2D_bounding_box.h:104
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
bool similar_boxes(const Bbox &model_box, const Bbox &data_box, double area_thresh_lower=0.6, double area_thresh_upper=1.2)
Check whether the deva detection box and the model box belong to the same object based on their overl...
Definition: pt_detection_box.cpp:54
std::string type
Definition: pt_detection_box.h:46
#define IFT(a, ex, msg)
Definition: l_exception.h:101
std::vector< Detection_box > parse_detection_file(const std::string &filename)
Read in a vector of Detection_box from a sigle file.
Definition: pt_detection_box.cpp:32
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Definition: perspective_camera.h:93
Detection_box parse_detection_box(const std::string &line)
Read in an Detection_box from a sigle line.
Definition: pt_detection_box.h:116
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
Bbox bbox
Definition: pt_detection_box.h:44
std::ostream & operator<<(std::ostream &ost, const Complete_state &cs)
outputs the Complete_state.
Definition: pt_complete_state.h:86
bool operator<(const Detection_box &b1, const Detection_box &b2)
Compares to boxes using middle of box. Needed because we have associated containers of these...
Definition: pt_detection_box.h:77
bool box_on_ground(const Detection_box &dbox, const Perspective_camera &cam)
Checks whether the bottom of a box back-projects to the ground.
Definition: pt_detection_box.h:164
Object thrown when input or output fails.
Definition: l_exception.h:496
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Vector get_bottom_center() const
Definition: gr_2D_bounding_box.h:105