[Bf-blender-cvs] [7d0653a] soc-2016-multiview: fix a bug in CameraPoseForFrame()

Tianwei Shen noreply at git.blender.org
Tue Jun 28 18:37:06 CEST 2016


Commit: 7d0653a08fb4ea909a29a6b95df24d177fe7cddf
Author: Tianwei Shen
Date:   Tue Jun 28 23:47:29 2016 +0800
Branches: soc-2016-multiview
https://developer.blender.org/rB7d0653a08fb4ea909a29a6b95df24d177fe7cddf

fix a bug in CameraPoseForFrame()

===================================================================

M	intern/libmv/intern/reconstructionN.cc
M	intern/libmv/libmv/autotrack/bundle.cc
M	intern/libmv/libmv/autotrack/intersect.cc
M	intern/libmv/libmv/autotrack/pipeline.cc
M	intern/libmv/libmv/autotrack/reconstruction.cc
M	intern/libmv/libmv/autotrack/reconstruction.h
M	intern/libmv/libmv/autotrack/resect.cc
M	source/blender/blenkernel/intern/tracking_correspondence.c

===================================================================

diff --git a/intern/libmv/intern/reconstructionN.cc b/intern/libmv/intern/reconstructionN.cc
index c019a83..b40c89f 100644
--- a/intern/libmv/intern/reconstructionN.cc
+++ b/intern/libmv/intern/reconstructionN.cc
@@ -176,13 +176,12 @@ libmv_ReconstructionN** libmv_solveMultiviewReconstruction(
 	for(int i = 0; i < clip_num; i++)
 	{
 		all_libmv_reconstruction[i] = LIBMV_OBJECT_NEW(libmv_ReconstructionN);
-		Tracks &tracks = *((Tracks *) all_libmv_tracks[i]);
+		Tracks &tracks = *((Tracks *) all_libmv_tracks[i]);		// Tracks are just a bunch of markers
 
 		///* Retrieve reconstruction options from C-API to libmv API. */
 		CameraIntrinsics *camera_intrinsics;
 		camera_intrinsics = all_libmv_reconstruction[i]->intrinsics =
 		        libmv_cameraIntrinsicsCreateFromOptions(&all_libmv_camera_intrinsics_options[i]);
-		printf("camera %d size: %d, %d\n", i, camera_intrinsics->image_width(), camera_intrinsics->image_height());
 
 		///* Invert the camera intrinsics/ */
 		Tracks normalized_tracks;
@@ -241,11 +240,11 @@ libmv_ReconstructionN** libmv_solveMultiviewReconstruction(
 	}
 	// bundle the two-view initial reconstruction
 	// (it is redundant for now since now 3d point is added at this stage)
-	if(!mv::EuclideanBundleAll(all_normalized_tracks, &reconstruction)) {
-		printf("mv::EuclideanBundleAll failed\n");
-		all_libmv_reconstruction[0]->is_valid = false;
-		return all_libmv_reconstruction;
-	}
+	//if(!mv::EuclideanBundleAll(all_normalized_tracks, &reconstruction)) {
+	//	printf("mv::EuclideanBundleAll failed\n");
+	//	all_libmv_reconstruction[0]->is_valid = false;
+	//	return all_libmv_reconstruction;
+	//}
 	if(!mv::EuclideanCompleteMultiviewReconstruction(all_normalized_tracks, &reconstruction, &update_callback)) {
 		printf("mv::EuclideanReconstructionComplete failed\n");
 		all_libmv_reconstruction[0]->is_valid = false;
diff --git a/intern/libmv/libmv/autotrack/bundle.cc b/intern/libmv/libmv/autotrack/bundle.cc
index 1113e7b..a96e4c2 100644
--- a/intern/libmv/libmv/autotrack/bundle.cc
+++ b/intern/libmv/libmv/autotrack/bundle.cc
@@ -561,17 +561,17 @@ void EuclideanBundleCommonIntrinsics(
       num_residuals++;
     }
   }
-  LG << "Number of residuals: " << num_residuals;
+  std::cout << "Number of residuals: " << num_residuals << "\n";
 
   if (!num_residuals) {
-    LG << "Skipping running minimizer with zero residuals";
+    std::cout << "Skipping running minimizer with zero residuals\n";
     return;
   }
 
   if (intrinsics->GetDistortionModelType() == libmv::DISTORTION_MODEL_DIVISION &&
     (bundle_intrinsics & BUNDLE_TANGENTIAL) != 0) {
     LOG(FATAL) << "Division model doesn't support bundling "
-                  "of tangential distortion";
+                  "of tangential distortion\n";
   }
 
   BundleIntrinsicsLogMessage(bundle_intrinsics);
diff --git a/intern/libmv/libmv/autotrack/intersect.cc b/intern/libmv/libmv/autotrack/intersect.cc
index 59f0820..cc8ee89 100644
--- a/intern/libmv/libmv/autotrack/intersect.cc
+++ b/intern/libmv/libmv/autotrack/intersect.cc
@@ -19,6 +19,7 @@
 // IN THE SOFTWARE.
 //
 // Author: Tianwei Shen <shentianweipku at gmail.com>
+// adapted from simple_pipeline/intersect.cc
 
 #include "libmv/autotrack/intersect.h"
 
@@ -85,10 +86,12 @@ bool EuclideanIntersect(const vector<Marker> &markers,
   vector<Mat34> cameras;
   Mat34 P;
   for (int i = 0; i < markers.size(); ++i) {
+    std::cout << "[Intersect] marker clip frame: " << markers[i].clip << " " << markers[i].frame << std::endl;
     CameraPose *camera = reconstruction->CameraPoseForFrame(markers[i].clip, markers[i].frame);
     libmv::P_From_KRt(K, camera->R, camera->t, &P);
     cameras.push_back(P);
   }
+  std::cout << "[Intersect] camera size: " << cameras.size() << std::endl;
 
   // Stack the 2D coordinates together as required by NViewTriangulate.
   Mat2X points(2, markers.size());
@@ -98,7 +101,7 @@ bool EuclideanIntersect(const vector<Marker> &markers,
   }
 
   Vec4 Xp;
-  LG << "Intersecting with " << markers.size() << " markers.";
+  std::cout << "Intersecting with " << markers.size() << " markers.\n";
   libmv::NViewTriangulateAlgebraic(points, cameras, &Xp);
 
   // Get euclidean version of the homogeneous point.
@@ -129,9 +132,9 @@ bool EuclideanIntersect(const vector<Marker> &markers,
   // TODO(sergey): Once we'll update Ceres to the next version
   // we wouldn't need this check anymore -- Ceres will deal with
   // zero-sized problems nicely.
-  LG << "Number of residuals: " << num_residuals;
+  std::cout << "Number of residuals: " << num_residuals << "\n";
   if (!num_residuals) {
-    LG << "Skipping running minimizer with zero residuals";
+    std::cout << "Skipping running minimizer with zero residuals\n";
 
 	// We still add 3D point for the track regardless it was
 	// optimized or not. If track is a constant zero it'll use
@@ -177,86 +180,4 @@ bool EuclideanIntersect(const vector<Marker> &markers,
   return true;
 }
 
-//namespace {
-//
-//struct ProjectiveIntersectCostFunction {
-// public:
-//  typedef Vec  FMatrixType;
-//  typedef Vec4 XMatrixType;
-//
-//  ProjectiveIntersectCostFunction(
-//      const vector<Marker> &markers,
-//      const ProjectiveReconstruction &reconstruction)
-//    : markers(markers), reconstruction(reconstruction) {}
-//
-//  Vec operator()(const Vec4 &X) const {
-//    Vec residuals(2 * markers.size());
-//    residuals.setZero();
-//    for (int i = 0; i < markers.size(); ++i) {
-//      const ProjectiveCamera &camera =
-//          *reconstruction.CameraForImage(markers[i].image);
-//      Vec3 projected = camera.P * X;
-//      projected /= projected(2);
-//      residuals[2*i + 0] = projected(0) - markers[i].x;
-//      residuals[2*i + 1] = projected(1) - markers[i].y;
-//    }
-//    return residuals;
-//  }
-//  const vector<Marker> &markers;
-//  const ProjectiveReconstruction &reconstruction;
-//};
-//
-//}  // namespace
-//
-//bool ProjectiveIntersect(const vector<Marker> &markers,
-//                         ProjectiveReconstruction *reconstruction) {
-//  if (markers.size() < 2) {
-//    return false;
-//  }
-//
-//  // Get the cameras to use for the intersection.
-//  vector<Mat34> cameras;
-//  for (int i = 0; i < markers.size(); ++i) {
-//    ProjectiveCamera *camera = reconstruction->CameraForImage(markers[i].image);
-//    cameras.push_back(camera->P);
-//  }
-//
-//  // Stack the 2D coordinates together as required by NViewTriangulate.
-//  Mat2X points(2, markers.size());
-//  for (int i = 0; i < markers.size(); ++i) {
-//    points(0, i) = markers[i].x;
-//    points(1, i) = markers[i].y;
-//  }
-//
-//  Vec4 X;
-//  LG << "Intersecting with " << markers.size() << " markers.";
-//  NViewTriangulateAlgebraic(points, cameras, &X);
-//  X /= X(3);
-//
-//  typedef LevenbergMarquardt<ProjectiveIntersectCostFunction> Solver;
-//
-//  ProjectiveIntersectCostFunction triangulate_cost(markers, *reconstruction);
-//  Solver::SolverParameters params;
-//  Solver solver(triangulate_cost);
-//
-//  Solver::Results results = solver.minimize(params, &X);
-//  (void) results;  // TODO(keir): Ensure results are good.
-//
-//  // Try projecting the point; make sure it's in front of everyone.
-//  for (int i = 0; i < cameras.size(); ++i) {
-//    const ProjectiveCamera &camera =
-//        *reconstruction->CameraForImage(markers[i].image);
-//    Vec3 x = camera.P * X;
-//    if (x(2) < 0) {
-//      LOG(ERROR) << "POINT BEHIND CAMERA " << markers[i].image
-//                 << ": " << x.transpose();
-//    }
-//  }
-//
-//  reconstruction->InsertPoint(markers[0].track, X);
-//
-//  // TODO(keir): Add proper error checking.
-//  return true;
-//}
-
 }  // namespace mv
diff --git a/intern/libmv/libmv/autotrack/pipeline.cc b/intern/libmv/libmv/autotrack/pipeline.cc
index e29ea09..cdd417f 100644
--- a/intern/libmv/libmv/autotrack/pipeline.cc
+++ b/intern/libmv/libmv/autotrack/pipeline.cc
@@ -110,9 +110,9 @@ bool InternalCompleteReconstruction(
     libmv::ProgressUpdateCallback *update_callback = NULL) {
 
 	int clip_num = tracks.GetClipNum();
-	int max_frames = 0;		// maximum frame of all clips
+	int num_frames = 0;
 	for(int i = 0; i < clip_num; i++) {
-		max_frames += tracks.MaxFrame(i) + 1;
+		num_frames += tracks.MaxFrame(i) + 1;
 	}
 
 	int max_track = tracks.MaxTrack();
@@ -120,7 +120,7 @@ bool InternalCompleteReconstruction(
 	int num_intersects = -1;
 	int total_resects = 0;
 	std::cout << "Max track: " << max_track << "\n";
-	std::cout << "Max image: " << max_frames << "\n";
+	std::cout << "Number of total frames: " << num_frames << "\n";
 	std::cout << "Number of markers: " << tracks.NumMarkers() << "\n";
 	while (num_resects != 0 || num_intersects != 0) {
 		// Do all possible intersections.
@@ -143,7 +143,7 @@ bool InternalCompleteReconstruction(
 			std::cout << "Got " << reconstructed_markers.size() << " reconstructed markers for track " << track << "\n";
 			if (reconstructed_markers.size() >= 2) {
 				CompleteReconstructionLogProgress(update_callback,
-				                                  (double)total_resects/(max_frames));
+				                                  (double)total_resects/(num_frames));
 				if (PipelineRoutines::Intersect(reconstructed_markers,
 				                                reconstruction)) {
 					num_intersects++;
@@ -153,9 +153,10 @@ bool InternalCompleteReconstruction(
 				}
 			}
 		}
+		// bundle the newly added points
 		if (num_intersects) {
 			CompleteReconstructionLogProgress(update_callback,
-			                                  (double)total_resects/(max_frames),
+			                                  (double)total_resects/(num_frames),
 			                                  "Bundling...");
 			PipelineRoutines::Bundle(tracks, reconstruction);
 			std::cout << "Ran Bundle() after intersections.\n";
@@ -168,12 +169,12 @@ bool InternalCompleteReconstruction(
 			const int max_image = tracks.MaxFrame(clip);
 			for (int image = 0; image <= max_image; ++image) {
 				if (reconstruction->CameraPoseForFrame(clip, image)) {	// this camera pose has been added
-					LG << "Skipping frame: " << image;
+					std::cout << "Skipping frame: " << clip << " " << image << "\n";
 					continue;
 				}
 				vector<Marker> all_markers;
 				tracks.

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list