Commit: 2ce153377a54862bdcb5d8b62f35b139a7cf8aa2
Author: Tianwei Shen
Date:   Thu Jun 9 23:40:59 2016 +0800
Branches: soc-2016-multiview
https://developer.blender.org/rB2ce153377a54862bdcb5d8b62f35b139a7cf8aa2

add reconstruction.cc in autotrack

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

M       intern/libmv/CMakeLists.txt
M       intern/libmv/intern/reconstructionN.cc
A       intern/libmv/libmv/autotrack/reconstruction.cc
M       intern/libmv/libmv/autotrack/reconstruction.h

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

diff --git a/intern/libmv/CMakeLists.txt b/intern/libmv/CMakeLists.txt
index bf0ad3f..c7d75ed 100644
--- a/intern/libmv/CMakeLists.txt
+++ b/intern/libmv/CMakeLists.txt
@@ -76,6 +76,7 @@ if(WITH_LIBMV)
                intern/tracksN.cc
                libmv/autotrack/autotrack.cc
                libmv/autotrack/predict_tracks.cc
+               libmv/autotrack/reconstruction.cc
                libmv/autotrack/tracks.cc
                libmv/base/aligned_malloc.cc
                libmv/image/array_nd.cc
diff --git a/intern/libmv/intern/reconstructionN.cc 
b/intern/libmv/intern/reconstructionN.cc
index e0dae97..61954cc 100644
--- a/intern/libmv/intern/reconstructionN.cc
+++ b/intern/libmv/intern/reconstructionN.cc
@@ -115,11 +115,13 @@ libmv_ReconstructionN** 
libmv_solveMultiviewReconstruction(const int clip_num,
        libmv_ReconstructionN **all_libmv_reconstruction = 
LIBMV_STRUCT_NEW(libmv_ReconstructionN*, clip_num);
        libmv::vector<Marker> keyframe_markers;
        int keyframe1, keyframe2;
+
+       // make reconstrution on the primary clip reconstruction
+       Reconstruction &reconstruction = 
all_libmv_reconstruction[0]->reconstruction;
        for(int i = 0; i < clip_num; i++)
        {
                all_libmv_reconstruction[i] = 
LIBMV_OBJECT_NEW(libmv_ReconstructionN);
                Tracks &tracks = *((Tracks *) all_libmv_tracks[i]);
-               Reconstruction &reconstruction = 
all_libmv_reconstruction[i]->reconstruction;
 
                ///* Retrieve reconstruction options from C-API to libmv API. */
                CameraIntrinsics *camera_intrinsics;
@@ -136,7 +138,6 @@ libmv_ReconstructionN** 
libmv_solveMultiviewReconstruction(const int clip_num,
                        ///* keyframe selection. */
                        keyframe1 = libmv_reconstruction_options->keyframe1, 
keyframe2 = libmv_reconstruction_options->keyframe2;
                        normalized_tracks.GetMarkersForTracksInBothImages(i, 
keyframe1, i, keyframe2, &keyframe_markers);
-
                }
        }
 
@@ -144,7 +145,8 @@ libmv_ReconstructionN** 
libmv_solveMultiviewReconstruction(const int clip_num,
        printf("number of markers for init: %d\n", keyframe_markers.size());
        if (keyframe_markers.size() < 8) {
                LG << "No enough markers to initialize from";
-               all_libmv_reconstruction[0]->is_valid = false;
+               for(int i = 0; i < clip_num; i++)
+                       all_libmv_reconstruction[i]->is_valid = false;
                return all_libmv_reconstruction;
        }
 
@@ -153,7 +155,7 @@ libmv_ReconstructionN** 
libmv_solveMultiviewReconstruction(const int clip_num,
                MultiviewReconstructUpdateCallback(progress_update_callback,
                                                   callback_customdata);
 
-       // TODO(tianwei): skip the automatic keyframe selection
+       // TODO(tianwei): skip the automatic keyframe selection for now
        //if (libmv_reconstruction_options->select_keyframes) {
        //      LG << "Using automatic keyframe selection";
 
@@ -173,7 +175,14 @@ libmv_ReconstructionN** 
libmv_solveMultiviewReconstruction(const int clip_num,
        ///* Actual reconstruction. */
        update_callback.invoke(0, "Initial reconstruction");
 
-       //EuclideanReconstructTwoFrames(keyframe_markers, &reconstruction);
+       ///* TODO(tianwei): chain the tracks and correspondences */
+
+       if(!mv::ReconstructTwoFrames(keyframe_markers, &reconstruction)) {
+               printf("mv::ReconstrucTwoFrames failed\n");
+               for(int i = 0; i < clip_num; i++)
+                       all_libmv_reconstruction[i]->is_valid = false;
+               return all_libmv_reconstruction;
+       }
        //EuclideanBundle(normalized_tracks, &reconstruction);
        //EuclideanCompleteReconstruction(normalized_tracks,
        //                                &reconstruction,
@@ -202,9 +211,7 @@ libmv_ReconstructionN** 
libmv_solveMultiviewReconstruction(const int clip_num,
        //                     callback_customdata);
 
        for(int i = 0; i < clip_num; i++)
-       {
                all_libmv_reconstruction[i]->is_valid = true;
-       }
 
        return all_libmv_reconstruction;
 }
diff --git a/intern/libmv/libmv/autotrack/reconstruction.cc 
b/intern/libmv/libmv/autotrack/reconstruction.cc
new file mode 100644
index 0000000..73fc02c
--- /dev/null
+++ b/intern/libmv/libmv/autotrack/reconstruction.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2016 libmv authors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//
+// Author: [email protected] (Tianwei Shen)
+
+#include "libmv/autotrack/reconstruction.h"
+#include "libmv/autotrack/marker.h"
+#include "libmv/autotrack/tracks.h"
+#include "libmv/numeric/numeric.h"
+#include "libmv/logging/logging.h"
+
+using mv::Marker;
+using mv::Tracks;
+
+namespace mv {
+
+bool ReconstructTwoFrames(const vector<Marker> &markers,
+                          Reconstruction *reconstruction)
+{
+       if (markers.size() < 16) {
+               LG << "Not enough markers to initialize from two frames: " << 
markers.size();
+               return false;
+       }
+
+       int image1, image2;
+       //GetImagesInMarkers(markers, &image1, &image2);
+
+       //Mat x1, x2;
+       //CoordinatesForMarkersInImage(markers, image1, &x1);
+       //CoordinatesForMarkersInImage(markers, image2, &x2);
+
+       //Mat3 F;
+       //NormalizedEightPointSolver(x1, x2, &F);
+
+       //// The F matrix should be an E matrix, but squash it just to be sure.
+       //Mat3 E;
+       //FundamentalToEssential(F, &E);
+
+       //// Recover motion between the two images. Since this function assumes 
a
+       //// calibrated camera, use the identity for K.
+       //Mat3 R;
+       //Vec3 t;
+       //Mat3 K = Mat3::Identity();
+       //if (!MotionFromEssentialAndCorrespondence(E,
+       //                                          K, x1.col(0),
+       //                                          K, x2.col(0),
+       //                                          &R, &t)) {
+       //      LG << "Failed to compute R and t from E and K.";
+       //      return false;
+       //}
+
+       //// Image 1 gets the reference frame, image 2 gets the relative motion.
+       //reconstruction->InsertCamera(image1, Mat3::Identity(), Vec3::Zero());
+       //reconstruction->InsertCamera(image2, R, t);
+
+       //LG << "From two frame reconstruction got:\nR:\n" << R
+       //   << "\nt:" << t.transpose();
+       return true;
+}
+
+}  // namespace mv
diff --git a/intern/libmv/libmv/autotrack/reconstruction.h 
b/intern/libmv/libmv/autotrack/reconstruction.h
index 48bfa70..0a9fd29 100644
--- a/intern/libmv/libmv/autotrack/reconstruction.h
+++ b/intern/libmv/libmv/autotrack/reconstruction.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014 libmv authors.
+// Copyright (c) 2014, 2016 libmv authors.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to
@@ -19,6 +19,7 @@
 // IN THE SOFTWARE.
 //
 // Author: [email protected] (Keir Mierle)
+//         [email protected] (Tianwei Shen)
 
 #ifndef LIBMV_AUTOTRACK_RECONSTRUCTION_H_
 #define LIBMV_AUTOTRACK_RECONSTRUCTION_H_
@@ -35,6 +36,8 @@ using libmv::Mat3;
 using libmv::Vec3;
 
 class Model;
+struct Marker;
+class Tracks;
 
 class CameraPose {
   int clip;
@@ -86,6 +89,8 @@ class Reconstruction {
   vector<Model*> models_;
 };
 
+bool ReconstructTwoFrames(const vector<Marker> &markers,
+                          Reconstruction *reconstruction);
 }  // namespace mv
 
 #endif  // LIBMV_AUTOTRACK_RECONSTRUCTION_H_

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to