Blender  V3.3
marker.h
Go to the documentation of this file.
1 // Copyright (c) 2014 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 //
21 // Author: mierle@gmail.com (Keir Mierle)
22 
23 #ifndef LIBMV_AUTOTRACK_MARKER_H_
24 #define LIBMV_AUTOTRACK_MARKER_H_
25 
26 #include <ostream>
27 
28 #include "libmv/autotrack/quad.h"
29 #include "libmv/autotrack/region.h"
30 #include "libmv/numeric/numeric.h"
31 
32 namespace mv {
33 
34 using libmv::Vec2f;
35 
36 // A marker is the 2D location of a tracked region (quad) in an image.
37 // Note that some of this information could be normalized by having a
38 // collection of inter-connected structs. Instead the "fat Marker" design below
39 // trades memory for data structure simplicity.
40 struct Marker {
41  int clip; // The clip this marker is from.
42  int frame; // The frame within the clip this marker is from.
43  int track; // The track this marker is from.
44 
45  // The center of the marker in frame coordinates. This is typically, but not
46  // always, the same as the center of the patch.
48 
49  // A frame-realtive quad defining the part of the image the marker covers.
50  // For reference markers, the pixels in the patch are the tracking pattern.
52 
53  // Some markers are less certain than others; the weight determines the
54  // amount this marker contributes to the error. 1.0 indicates normal
55  // contribution; 0.0 indicates a zero-weight track (and will be omitted from
56  // bundle adjustment).
57  float weight;
58 
59  enum Source {
60  MANUAL, // The user placed this marker manually.
61  DETECTED, // A keypoint detector found this point.
62  TRACKED, // The tracking algorithm placed this marker.
63  MATCHED, // A matching algorithm (e.g. SIFT or SURF or ORB) found this.
64  PREDICTED, // A motion model predicted this marker. This is needed for
65  // handling occlusions in some cases where an imaginary marker
66  // is placed to keep camera motion smooth.
67  };
69 
70  // Markers may be inliers or outliers if the tracking fails; this allows
71  // visualizing the markers in the image.
74 
75  // When doing correlation tracking, where to search in the current frame for
76  // the pattern from the reference frame, in absolute frame coordinates.
78 
79  // For tracked and matched markers, indicates what the reference was.
82 
83  // Model related information for non-point tracks.
84  //
85  // Some tracks are on a larger object, such as a plane or a line or perhaps
86  // another primitive (a rectangular prisim). This captures the information
87  // needed to say that for example a collection of markers belongs to model #2
88  // (and model #2 is a plane).
89  enum ModelType { POINT, PLANE, LINE, CUBE };
91 
92  // The model ID this track (e.g. the second model, which is a plane).
93  int model_id;
94 
95  // TODO(keir): Add a "int model_argument" to capture that e.g. a marker is on
96  // the 3rd face of a cube.
97 
98  enum Channel {
99  CHANNEL_R = (1 << 0),
100  CHANNEL_G = (1 << 1),
101  CHANNEL_B = (1 << 2),
102  };
103 
104  // Channels from the original frame which this marker is unable to see.
106 
107  // Offset everything (center, patch, search) by the given delta.
108  template <typename T>
109  void Offset(const T& offset) {
110  center += offset.template cast<float>();
111  patch.coordinates.rowwise() += offset.template cast<int>();
113  }
114 
115  // Shift the center to the given new position (and patch, search).
116  template <typename T>
117  void SetPosition(const T& new_center) {
118  Offset(new_center - center);
119  }
120 };
121 
122 inline std::ostream& operator<<(std::ostream& out, const Marker& marker) {
123  out << "{" << marker.clip << ", " << marker.frame << ", " << marker.track
124  << ", (" << marker.center.x() << ", " << marker.center.y() << ")"
125  << "}";
126  return out;
127 }
128 
129 } // namespace mv
130 
131 #endif // LIBMV_AUTOTRACK_MARKER_H_
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
#define T
VecMat::Vec2< float > Vec2f
Definition: Geom.h:20
Eigen::Vector2f Vec2f
Definition: numeric.h:125
std::ostream & operator<<(std::ostream &out, const Marker &marker)
Definition: marker.h:122
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
Region search_region
Definition: marker.h:77
void SetPosition(const T &new_center)
Definition: marker.h:117
int disabled_channels
Definition: marker.h:105
int frame
Definition: marker.h:42
int clip
Definition: marker.h:41
void Offset(const T &offset)
Definition: marker.h:109
float weight
Definition: marker.h:57
Vec2f center
Definition: marker.h:47
@ DETECTED
Definition: marker.h:61
@ PREDICTED
Definition: marker.h:64
@ TRACKED
Definition: marker.h:62
@ MATCHED
Definition: marker.h:63
@ MANUAL
Definition: marker.h:60
Quad2Df patch
Definition: marker.h:51
ModelType model_type
Definition: marker.h:90
@ PLANE
Definition: marker.h:89
@ POINT
Definition: marker.h:89
@ LINE
Definition: marker.h:89
@ UNKNOWN
Definition: marker.h:72
@ INLIER
Definition: marker.h:72
@ OUTLIER
Definition: marker.h:72
int reference_frame
Definition: marker.h:81
Source source
Definition: marker.h:68
Status status
Definition: marker.h:73
int model_id
Definition: marker.h:93
@ CHANNEL_B
Definition: marker.h:101
@ CHANNEL_G
Definition: marker.h:100
@ CHANNEL_R
Definition: marker.h:99
int track
Definition: marker.h:43
int reference_clip
Definition: marker.h:80
Eigen::Matrix< T, 4, D > coordinates
Definition: quad.h:50
void Offset(const T &offset)