34# define snprintf _snprintf
44struct EuclideanPipelineRoutines {
45 typedef EuclideanReconstruction Reconstruction;
46 typedef EuclideanCamera Camera;
47 typedef EuclideanPoint Point;
49 static void Bundle(
const Tracks&
tracks,
50 EuclideanReconstruction* reconstruction) {
55 EuclideanReconstruction* reconstruction,
61 EuclideanReconstruction* reconstruction) {
65 static Marker ProjectMarker(
const EuclideanPoint&
point,
66 const EuclideanCamera&
camera,
67 const CameraIntrinsics& intrinsics) {
69 projected /= projected(2);
71 Marker reprojected_marker;
74 &reprojected_marker.x,
75 &reprojected_marker.y);
77 reprojected_marker.image =
camera.image;
79 return reprojected_marker;
83struct ProjectivePipelineRoutines {
84 typedef ProjectiveReconstruction Reconstruction;
85 typedef ProjectiveCamera Camera;
86 typedef ProjectivePoint Point;
88 static void Bundle(
const Tracks&
tracks,
89 ProjectiveReconstruction* reconstruction) {
94 ProjectiveReconstruction* reconstruction,
102 ProjectiveReconstruction* reconstruction) {
106 static Marker ProjectMarker(
const ProjectivePoint&
point,
107 const ProjectiveCamera&
camera,
108 const CameraIntrinsics& intrinsics) {
110 projected /= projected(2);
112 Marker reprojected_marker;
115 &reprojected_marker.x,
116 &reprojected_marker.y);
118 reprojected_marker.image =
camera.image;
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));
146 update_callback->
invoke(progress, message);
150template <
typename PipelineRoutines>
153 typename PipelineRoutines::Reconstruction* reconstruction,
155 int max_track =
tracks.MaxTrack();
156 int max_image =
tracks.MaxImage();
157 int num_resects = -1;
158 int num_intersects = -1;
160 LG <<
"Max track: " << max_track;
161 LG <<
"Max image: " << max_image;
162 LG <<
"Number of markers: " <<
tracks.NumMarkers();
163 while (num_resects != 0 || num_intersects != 0) {
166 for (
int track = 0; track <= max_track; ++track) {
167 if (reconstruction->PointForTrack(track)) {
168 LG <<
"Skipping point: " << track;
172 LG <<
"Got " << all_markers.size() <<
" markers for track " << track;
175 for (
int i = 0; i < all_markers.size(); ++i) {
176 if (reconstruction->CameraForImage(all_markers[i].image)) {
177 reconstructed_markers.push_back(all_markers[i]);
180 LG <<
"Got " << reconstructed_markers.size()
181 <<
" reconstructed markers for track " << track;
182 if (reconstructed_markers.size() >= 2) {
184 double(tot_resects) / (max_image));
185 if (PipelineRoutines::Intersect(reconstructed_markers,
188 LG <<
"Ran Intersect() for track " << track;
190 LG <<
"Failed Intersect() for track " << track;
194 if (num_intersects) {
196 update_callback,
double(tot_resects) / (max_image),
"Bundling...");
197 PipelineRoutines::Bundle(
tracks, reconstruction);
198 LG <<
"Ran Bundle() after intersections.";
200 LG <<
"Did " << num_intersects <<
" intersects.";
205 if (reconstruction->CameraForImage(
image)) {
206 LG <<
"Skipping frame: " <<
image;
210 LG <<
"Got " << all_markers.size() <<
" markers for image " <<
image;
213 for (
int i = 0; i < all_markers.size(); ++i) {
214 if (reconstruction->PointForTrack(all_markers[i].track)) {
215 reconstructed_markers.push_back(all_markers[i]);
218 LG <<
"Got " << reconstructed_markers.size()
219 <<
" reconstructed markers for image " <<
image;
220 if (reconstructed_markers.size() >= 5) {
222 double(tot_resects) / (max_image));
223 if (PipelineRoutines::Resect(
224 reconstructed_markers, reconstruction,
false)) {
227 LG <<
"Ran Resect() for image " <<
image;
229 LG <<
"Failed Resect() for image " <<
image;
235 update_callback,
double(tot_resects) / (max_image),
"Bundling...");
236 PipelineRoutines::Bundle(
tracks, reconstruction);
238 LG <<
"Did " << num_resects <<
" resects.";
244 if (reconstruction->CameraForImage(
image)) {
245 LG <<
"Skipping frame: " <<
image;
251 for (
int i = 0; i < all_markers.size(); ++i) {
252 if (reconstruction->PointForTrack(all_markers[i].track)) {
253 reconstructed_markers.push_back(all_markers[i]);
256 if (reconstructed_markers.size() >= 5) {
258 double(tot_resects) / (max_image));
259 if (PipelineRoutines::Resect(
260 reconstructed_markers, reconstruction,
true)) {
262 LG <<
"Ran final Resect() for image " <<
image;
264 LG <<
"Failed final Resect() for image " <<
image;
270 update_callback,
double(tot_resects) / (max_image),
"Bundling...");
271 PipelineRoutines::Bundle(
tracks, reconstruction);
275template <
typename PipelineRoutines>
277 const Tracks& image_tracks,
278 const typename PipelineRoutines::Reconstruction& reconstruction,
281 int num_reprojected = 0;
282 double total_error = 0.0;
284 for (
int i = 0; i < markers.size(); ++i) {
285 double weight = markers[i].weight;
286 const typename PipelineRoutines::Camera*
camera =
287 reconstruction.CameraForImage(markers[i].
image);
288 const typename PipelineRoutines::Point*
point =
289 reconstruction.PointForTrack(markers[i].track);
296 Marker reprojected_marker =
297 PipelineRoutines::ProjectMarker(*
point, *
camera, intrinsics);
298 double ex = (reprojected_marker.
x - markers[i].x) * weight;
299 double ey = (reprojected_marker.
y - markers[i].y) * weight;
305 "image %-3d track %-3d "
314 reprojected_marker.
x,
315 reprojected_marker.
y,
318 sqrt(ex * ex + ey * ey));
321 total_error +=
sqrt(ex * ex + ey * ey);
323 LG <<
"Skipped " << num_skipped <<
" markers.";
324 LG <<
"Reprojected " << num_reprojected <<
" markers.";
325 LG <<
"Total error: " << total_error <<
" px";
326 LG <<
"Average error: " << (total_error / num_reprojected) <<
" px";
327 return total_error / num_reprojected;
334 image_tracks, reconstruction, intrinsics);
338 const Tracks& image_tracks,
342 image_tracks, reconstruction, intrinsics);
349 tracks, reconstruction, update_callback);
360 Tracks* calibrated_tracks) {
362 for (
int i = 0; i < markers.size(); ++i) {
364 markers[i].
x, markers[i].
y, &(markers[i].
x), &(markers[i].
y));
366 *calibrated_tracks =
Tracks(markers);
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
DBVT_INLINE bool Intersect(const btDbvtAabbMm &a, const btDbvtAabbMm &b)
virtual void ApplyIntrinsics(double normalized_x, double normalized_y, double *image_x, double *image_y) const =0
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
vector< Marker > AllMarkers() const
Returns all the markers.
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
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)
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
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)