KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pt_box_trajectory.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_box_trajectory.h 18329 2014-12-02 04:29:44Z ksimek $ */
20 
21 #ifndef PT_BOX_TRAJECTORY_H
22 #define PT_BOX_TRAJECTORY_H
23 
27 #include <m_cpp/m_vector.h>
28 #include <l_cpp/l_exception.h>
29 #include <detector_cpp/d_bbox.h>
30 #include <vector>
31 #include <limits>
32 #include <fstream>
33 #include <string>
34 #include <ios>
35 #include <iomanip>
36 
39 namespace kjb {
40 namespace pt {
41 
42 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
43 
47 
50 (
51  const Trajectory& traj,
52  const Perspective_camera& cam
53 );
54 
57 (
58  const Trajectory_map& trajs,
59  const Perspective_camera& cam
60 );
61 
64 (
65  const Trajectory& traj,
66  const Perspective_camera& cam
67 );
68 
71 (
72  const Trajectory_map& trajs,
73  const Perspective_camera& cam
74 );
75 
76 
77 }} //namespace kjb::pt
78 
79 namespace kjb {
80 namespace tracking {
81 
83 template <>
84 inline
85 bool kjb::pt::Box_trajectory_element::parse(const std::string& line)
86 {
87  using namespace std;
88  istringstream istr(line);
89  vector<double> elems;
90 
91  copy(istream_iterator<double>(istr), istream_iterator<double>(),
92  back_inserter(elems));
93 
94  IFT(elems.size() == 5, Runtime_error,
95  "Cannot read trajectory element: line has wrong format.");
96 
97  if(elems.back() == 0.0)
98  return false;
99 
100  // else
101  Vector center(elems[0], elems[1]);
102  double width = elems[2];
103  double height = elems[3];
104  value = Bbox(center, width, height);
105 
106  return true;
107 }
108 
110 template <>
111 inline
112 void kjb::pt::Box_trajectory_element::write(std::ofstream& ofs) const
113 {
114  ofs << value << " 1.0" << std::endl;
115 }
116 
118 template <>
119 inline
120 void kjb::pt::Box_trajectory_element::write_invalid(std::ofstream& ofs)
121 {
122  ofs << "-1.0 -1.0 0.0 0.0 0.0" << std::endl;
123 }
124 
125 } }
126 
127 
128 #endif /*PT_BOX_TRAJECTORY_H */
129 
Box_trajectory_map get_face_box_trajectory_map(const Trajectory_map &trajs, const Perspective_camera &cam)
Convert a Trajectory_map to a Box_trajectory_map.
Definition: pt_box_trajectory.cpp:122
Generic_trajectory< Bbox > Box_trajectory
Definition: pt_box_trajectory.h:45
Generic_trajectory_map< Bbox > Box_trajectory_map
Definition: pt_box_trajectory.h:44
Represents an element of a trajectory of a particular entity.
Definition: tracking_trajectory.h:61
Box_trajectory get_body_box_trajectory(const Trajectory &traj, const Perspective_camera &cam)
Convert a Trajectory to a Box_trajectory.
Definition: pt_box_trajectory.cpp:32
height
Definition: APPgetLargeConnectedEdges.m:33
Axis_aligned_rectangle_2d Bbox
Definition: d_bbox.h:29
void write(std::ofstream &ofs) const
Writes this element to a stream.
Definition: tracking_trajectory.h:79
#define IFT(a, ex, msg)
Definition: l_exception.h:101
Generic_trajectory_element< Bbox > Box_trajectory_element
Definition: pt_box_trajectory.h:46
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Definition: perspective_camera.h:93
Represents a set of trajectories; it is a map from entity to trajectory.
Definition: tracking_trajectory.h:53
bool parse(const std::string &line)
Reads an element from a line of a file.
Definition: tracking_trajectory.h:70
Box_trajectory_map get_body_box_trajectory_map(const Trajectory_map &trajs, const Perspective_camera &cam)
Convert a Trajectory_map to a Box_trajectory_map.
Definition: pt_box_trajectory.cpp:64
static void write_invalid(std::ofstream &ofs)
Writes this element to a stream.
Definition: tracking_trajectory.h:88
Represents a trajectory. Vector of optionals to trajectory elements.
Definition: tracking_trajectory.h:49
Box_trajectory get_face_box_trajectory(const Trajectory &traj, const Perspective_camera &cam)
Convert a Trajectory to a Box_trajectory.
Definition: pt_box_trajectory.cpp:83
Support for error handling exception classes in libKJB.
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...