34 # define snprintf _snprintf
44 struct EuclideanPipelineRoutines {
45 typedef EuclideanReconstruction Reconstruction;
46 typedef EuclideanCamera
Camera;
47 typedef EuclideanPoint
Point;
49 static void Bundle(
const Tracks&
tracks,
65 static Marker ProjectMarker(
const EuclideanPoint& point,
66 const EuclideanCamera& camera,
67 const CameraIntrinsics& intrinsics) {
68 Vec3 projected = camera.R * point.X + camera.t;
69 projected /= projected(2);
71 Marker reprojected_marker;
72 intrinsics.ApplyIntrinsics(projected(0),
74 &reprojected_marker.x,
75 &reprojected_marker.y);
77 reprojected_marker.image = camera.image;
78 reprojected_marker.track = point.track;
79 return reprojected_marker;
83 struct ProjectivePipelineRoutines {
84 typedef ProjectiveReconstruction Reconstruction;
85 typedef ProjectiveCamera
Camera;
86 typedef ProjectivePoint
Point;
88 static void Bundle(
const Tracks&
tracks,
106 static Marker ProjectMarker(
const ProjectivePoint& point,
107 const ProjectiveCamera& camera,
108 const CameraIntrinsics& intrinsics) {
109 Vec3 projected = camera.P * point.X;
110 projected /= projected(2);
112 Marker reprojected_marker;
113 intrinsics.ApplyIntrinsics(projected(0),
115 &reprojected_marker.x,
116 &reprojected_marker.y);
118 reprojected_marker.image = camera.image;
119 reprojected_marker.track = point.track;
120 return reprojected_marker;
129 const char* step =
NULL) {
130 if (update_callback) {
136 "Completing solution %d%% | %s",
137 (
int)(progress * 100),
142 "Completing solution %d%%",
143 (
int)(progress * 100));
145 update_callback->
invoke(progress, message);
149 template <
typename PipelineRoutines>
154 int max_track =
tracks.MaxTrack();
155 int max_image =
tracks.MaxImage();
156 int num_resects = -1;
157 int num_intersects = -1;
159 LG <<
"Max track: " << max_track;
160 LG <<
"Max image: " << max_image;
161 LG <<
"Number of markers: " <<
tracks.NumMarkers();
162 while (num_resects != 0 || num_intersects != 0) {
165 for (
int track = 0; track <= max_track; ++track) {
167 LG <<
"Skipping point: " << track;
171 LG <<
"Got " << all_markers.size() <<
" markers for track " << track;
174 for (
int i = 0; i < all_markers.size(); ++i) {
176 reconstructed_markers.push_back(all_markers[i]);
179 LG <<
"Got " << reconstructed_markers.size()
180 <<
" reconstructed markers for track " << track;
181 if (reconstructed_markers.size() >= 2) {
183 (
double)tot_resects / (max_image));
187 LG <<
"Ran Intersect() for track " << track;
189 LG <<
"Failed Intersect() for track " << track;
193 if (num_intersects) {
195 update_callback, (
double)tot_resects / (max_image),
"Bundling...");
197 LG <<
"Ran Bundle() after intersections.";
199 LG <<
"Did " << num_intersects <<
" intersects.";
203 for (
int image = 0; image <= max_image; ++image) {
205 LG <<
"Skipping frame: " << image;
209 LG <<
"Got " << all_markers.size() <<
" markers for image " << image;
212 for (
int i = 0; i < all_markers.size(); ++i) {
214 reconstructed_markers.push_back(all_markers[i]);
217 LG <<
"Got " << reconstructed_markers.size()
218 <<
" reconstructed markers for image " << image;
219 if (reconstructed_markers.size() >= 5) {
221 (
double)tot_resects / (max_image));
222 if (PipelineRoutines::Resect(
226 LG <<
"Ran Resect() for image " << image;
228 LG <<
"Failed Resect() for image " << image;
234 update_callback, (
double)tot_resects / (max_image),
"Bundling...");
237 LG <<
"Did " << num_resects <<
" resects.";
242 for (
int image = 0; image <= max_image; ++image) {
244 LG <<
"Skipping frame: " << image;
250 for (
int i = 0; i < all_markers.size(); ++i) {
252 reconstructed_markers.push_back(all_markers[i]);
255 if (reconstructed_markers.size() >= 5) {
257 (
double)tot_resects / (max_image));
258 if (PipelineRoutines::Resect(
261 LG <<
"Ran final Resect() for image " << image;
263 LG <<
"Failed final Resect() for image " << image;
269 update_callback, (
double)tot_resects / (max_image),
"Bundling...");
274 template <
typename PipelineRoutines>
276 const Tracks& image_tracks,
280 int num_reprojected = 0;
281 double total_error = 0.0;
283 for (
int i = 0; i <
markers.size(); ++i) {
284 double weight =
markers[i].weight;
287 const typename PipelineRoutines::Point* point =
289 if (!camera || !point || weight == 0.0) {
295 Marker reprojected_marker =
296 PipelineRoutines::ProjectMarker(*point, *camera, intrinsics);
297 double ex = (reprojected_marker.
x -
markers[i].x) * weight;
298 double ey = (reprojected_marker.
y -
markers[i].y) * weight;
304 "image %-3d track %-3d "
313 reprojected_marker.
x,
314 reprojected_marker.
y,
317 sqrt(ex * ex + ey * ey));
320 total_error +=
sqrt(ex * ex + ey * ey);
322 LG <<
"Skipped " << num_skipped <<
" markers.";
323 LG <<
"Reprojected " << num_reprojected <<
" markers.";
324 LG <<
"Total error: " << total_error <<
" px";
325 LG <<
"Average error: " << (total_error / num_reprojected) <<
" px";
326 return total_error / num_reprojected;
332 return InternalReprojectionError<EuclideanPipelineRoutines>(
337 const Tracks& image_tracks,
340 return InternalReprojectionError<ProjectivePipelineRoutines>(
347 InternalCompleteReconstruction<EuclideanPipelineRoutines>(
353 InternalCompleteReconstruction<ProjectivePipelineRoutines>(
tracks,
359 Tracks* calibrated_tracks) {
361 for (
int i = 0; i <
markers.size(); ++i) {
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
DBVT_INLINE bool Intersect(const btDbvtAabbMm &a, const btDbvtAabbMm &b)
virtual void InvertIntrinsics(double image_x, double image_y, double *normalized_x, double *normalized_y) const =0
virtual void invoke(double progress, const char *message)=0
ProjectivePoint * PointForTrack(int track)
Returns a pointer to the point corresponding to track.
ProjectiveCamera * CameraForImage(int image)
Returns a pointer to the camera corresponding to image.
vector< Marker > AllMarkers() const
Returns all the markers.
const vector< Marker > & markers
const ProjectiveReconstruction & reconstruction
double ProjectiveReprojectionError(const Tracks &image_tracks, const ProjectiveReconstruction &reconstruction, const CameraIntrinsics &intrinsics)
void ProjectiveBundle(const Tracks &, ProjectiveReconstruction *)
bool ProjectiveResect(const vector< Marker > &markers, ProjectiveReconstruction *reconstruction)
bool EuclideanResect(const vector< Marker > &markers, EuclideanReconstruction *reconstruction, bool final_pass)
static void CompleteReconstructionLogProgress(ProgressUpdateCallback *update_callback, double progress, const char *step=NULL)
void EuclideanBundle(const Tracks &tracks, EuclideanReconstruction *reconstruction)
void EuclideanCompleteReconstruction(const Tracks &tracks, EuclideanReconstruction *reconstruction, ProgressUpdateCallback *update_callback)
bool EuclideanIntersect(const vector< Marker > &markers, EuclideanReconstruction *reconstruction)
double InternalReprojectionError(const Tracks &image_tracks, const typename PipelineRoutines::Reconstruction &reconstruction, const CameraIntrinsics &intrinsics)
double EuclideanReprojectionError(const Tracks &image_tracks, const EuclideanReconstruction &reconstruction, const CameraIntrinsics &intrinsics)
void InvertIntrinsicsForTracks(const Tracks &raw_tracks, const CameraIntrinsics &camera_intrinsics, Tracks *calibrated_tracks)
bool ProjectiveIntersect(const vector< Marker > &markers, ProjectiveReconstruction *reconstruction)
void InternalCompleteReconstruction(const Tracks &tracks, typename PipelineRoutines::Reconstruction *reconstruction, ProgressUpdateCallback *update_callback=NULL)
void ProjectiveCompleteReconstruction(const Tracks &tracks, ProjectiveReconstruction *reconstruction)