[Bf-blender-cvs] [606329d] master: Libmv: Replace region tracker with autotracker in Blender

Sergey Sharybin noreply at git.blender.org
Thu Oct 30 19:32:14 CET 2014


Commit: 606329d0f872d675faf9362f9d2f89cf0551dd25
Author: Sergey Sharybin
Date:   Sun Jun 22 20:19:48 2014 +0600
Branches: master
https://developer.blender.org/rB606329d0f872d675faf9362f9d2f89cf0551dd25

Libmv: Replace region tracker with autotracker in Blender

The title actually tells it all, this commit switches Blender to use the new
autotrack API from Libmv.

>From the user point of view it means that prediction model is now used when
tracking which gives really nice results.

All the other changes are not really visible for users, those are just frame
accessors, caches and so for the new API.

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

M	extern/libmv/intern/autotrack.cc
M	source/blender/blenkernel/BKE_tracking.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/tracking_auto.c
M	source/blender/blenkernel/intern/tracking_region_tracker.c
M	source/blender/blenkernel/intern/tracking_util.c
M	source/blender/blenkernel/tracking_private.h
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_clip/tracking_ops.c

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

diff --git a/extern/libmv/intern/autotrack.cc b/extern/libmv/intern/autotrack.cc
index 6ddb1af..f0cbc68 100644
--- a/extern/libmv/intern/autotrack.cc
+++ b/extern/libmv/intern/autotrack.cc
@@ -67,21 +67,12 @@ int libmv_autoTrackMarker(libmv_AutoTrack* libmv_autotrack,
   libmv_apiMarkerToMarker(*libmv_tracked_marker, &tracked_marker);
   libmv_configureTrackRegionOptions(*libmv_options,
                                     &options);
-
-  bool tracking_result
-    = ((AutoTrack*) libmv_autotrack)->TrackMarker(&tracked_marker,
-                                                  &result,
-                                                  &options);
+  (((AutoTrack*) libmv_autotrack)->TrackMarker(&tracked_marker,
+                                               &result,
+                                               &options));
   libmv_markerToApiMarker(tracked_marker, libmv_tracked_marker);
   libmv_regionTrackergetResult(result, libmv_result);
-
-  // TODO(keir): Update the termination string with failure details.
-  if (result.termination == TrackRegionResult::CONVERGENCE ||
-      result.termination == TrackRegionResult::NO_CONVERGENCE) {
-    tracking_result = true;
-  }
-
-  return tracking_result;
+  return result.is_usable();
 }
 
 void libmv_autoTrackAddMarker(libmv_AutoTrack* libmv_autotrack,
diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h
index 8bc619c..5f5cb4c 100644
--- a/source/blender/blenkernel/BKE_tracking.h
+++ b/source/blender/blenkernel/BKE_tracking.h
@@ -210,16 +210,18 @@ void BKE_tracking_disable_channels(struct ImBuf *ibuf, bool disable_red, bool di
                                    bool disable_blue, bool grayscale);
 
 /* **** 2D tracking **** */
-struct MovieTrackingContext *BKE_tracking_context_new(struct MovieClip *clip, struct MovieClipUser *user,
-                                                      const bool backwards, const bool sequence);
-void BKE_tracking_context_free(struct MovieTrackingContext *context);
-void BKE_tracking_context_sync(struct MovieTrackingContext *context);
-void BKE_tracking_context_sync_user(const struct MovieTrackingContext *context, struct MovieClipUser *user);
-bool BKE_tracking_context_step(struct MovieTrackingContext *context);
-void BKE_tracking_context_finish(struct MovieTrackingContext *context);
-
 void BKE_tracking_refine_marker(struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, bool backwards);
 
+/* *** 2D auto track  *** */
+
+struct AutoTrackContext *BKE_autotrack_context_new(struct MovieClip *clip, struct MovieClipUser *user,
+                                                   const bool backwards, const bool sequence);
+bool BKE_autotrack_context_step(struct AutoTrackContext *context);
+void BKE_autotrack_context_sync(struct AutoTrackContext *context);
+void BKE_autotrack_context_sync_user(struct AutoTrackContext *context, struct MovieClipUser *user);
+void BKE_autotrack_context_finish(struct AutoTrackContext *context);
+void BKE_autotrack_context_free(struct AutoTrackContext *context);
+
 /* **** Plane tracking **** */
 
 void BKE_tracking_track_plane_from_existing_motion(struct MovieTrackingPlaneTrack *plane_track, int start_frame);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index f4a3a0c..6550882 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -158,6 +158,7 @@ set(SRC
 	intern/text.c
 	intern/texture.c
 	intern/tracking.c
+	intern/tracking_auto.c
 	intern/tracking_detect.c
 	intern/tracking_plane_tracker.c
 	intern/tracking_region_tracker.c
diff --git a/source/blender/blenkernel/intern/tracking_auto.c b/source/blender/blenkernel/intern/tracking_auto.c
new file mode 100644
index 0000000..2cd13a9
--- /dev/null
+++ b/source/blender/blenkernel/intern/tracking_auto.c
@@ -0,0 +1,563 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation,
+ *                 Sergey Sharybin
+ *                 Keir Mierle
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/tracking_auto.c
+ *  \ingroup bke
+ */
+
+#include <stdlib.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_movieclip_types.h"
+#include "DNA_object_types.h"   /* SELECT */
+
+#include "BLI_threads.h"
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+
+#include "BKE_movieclip.h"
+#include "BKE_tracking.h"
+
+#include "libmv-capi.h"
+#include "tracking_private.h"
+
+typedef struct AutoTrackOptions {
+	int clip_index;  /** Index of the clip this track belogs to. */
+	int track_index;  /* Index of the track in AutoTrack tracks structure. */
+	MovieTrackingTrack *track;  /* Pointer to an original track/ */
+	libmv_TrackRegionOptions track_region_options;  /* Options for the region
+	                                                   tracker. */
+	bool use_keyframe_match;  /* Keyframe pattern matching. */
+
+	/* TODO(sergey): A bit awkward to keep it in here, only used to
+	 * place a disabled marker once the trackign fails,
+	 * Wither find a more clear way to do it or call it track context
+	 * or state, not options.
+	 */
+	bool is_failed;
+	int failed_frame;
+} AutoTrackOptions;
+
+typedef struct AutoTrackContext {
+	MovieClip *clips[MAX_ACCESSOR_CLIP];
+	int num_clips;
+
+	MovieClipUser user;
+	int frame_width, frame_height;
+
+	struct libmv_AutoTrack *autotrack;
+	TrackingImageAccessor *image_accessor;
+
+	int num_tracks;  /* Number of tracks being tracked. */
+	AutoTrackOptions *options;  /* Per-tracking track options. */
+
+	bool backwards;
+	bool sequence;
+	int first_frame;
+	int sync_frame;
+	bool first_sync;
+	SpinLock spin_lock;
+} AutoTrackContext;
+
+static void normalized_to_libmv_frame(const float normalized[2],
+                                      const int frame_dimensions[2],
+                                      float result[2])
+{
+	result[0] = normalized[0] * frame_dimensions[0] - 0.5f;
+	result[1] = normalized[1] * frame_dimensions[1] - 0.5f;
+}
+
+static void normalized_relative_to_libmv_frame(const float normalized[2],
+                                               const float origin[2],
+                                               const int frame_dimensions[2],
+                                               float result[2])
+{
+	result[0] = (normalized[0] + origin[0]) * frame_dimensions[0] - 0.5f;
+	result[1] = (normalized[1] + origin[1]) * frame_dimensions[1] - 0.5f;
+}
+
+static void libmv_frame_to_normalized(const float frame_coord[2],
+                                      const int frame_dimensions[2],
+                                      float result[2])
+{
+	result[0] = (frame_coord[0] + 0.5f) / frame_dimensions[0];
+	result[1] = (frame_coord[1] + 0.5f) / frame_dimensions[1];
+}
+
+static void libmv_frame_to_normalized_relative(const float frame_coord[2],
+                                               const float origin[2],
+                                               const int frame_dimensions[2],
+                                               float result[2])
+{
+	result[0] = (frame_coord[0] - origin[0]) / frame_dimensions[0];
+	result[1] = (frame_coord[1] - origin[1]) / frame_dimensions[1];
+}
+
+static void dna_marker_to_libmv_marker(/*const*/ MovieTrackingTrack *track,
+                                       /*const*/ MovieTrackingMarker *marker,
+                                       int clip,
+                                       int track_index,
+                                       int frame_width,
+                                       int frame_height,
+                                       bool backwards,
+                                       libmv_Marker *libmv_marker)
+{
+	const int frame_dimensions[2] = {frame_width, frame_height};
+	int i;
+	libmv_marker->clip = clip;
+	libmv_marker->frame = marker->framenr;
+	libmv_marker->track = track_index;
+
+	normalized_to_libmv_frame(marker->pos,
+	                          frame_dimensions,
+	                          libmv_marker->center);
+	for (i = 0; i < 4; ++i) {
+		normalized_relative_to_libmv_frame(marker->pattern_corners[i],
+		                                   marker->pos,
+		                                   frame_dimensions,
+		                                   libmv_marker->patch[i]);
+	}
+
+	normalized_relative_to_libmv_frame(marker->search_min,
+	                                   marker->pos,
+	                                   frame_dimensions,
+	                                   libmv_marker->search_region_min);
+
+	normalized_relative_to_libmv_frame(marker->search_max,
+	                                   marker->pos,
+	                                   frame_dimensions,
+	                                   libmv_marker->search_region_max);
+
+	/* TODO(sergey): All the markers does have 1.0 weight. */
+	libmv_marker->weight = 1.0f;
+
+	if (marker->flag & MARKER_TRACKED) {
+		libmv_marker->source = LIBMV_MARKER_SOURCE_TRACKED;
+	}
+	else {
+		libmv_marker->source = LIBMV_MARKER_SOURCE_MANUAL;
+	}
+	libmv_marker->status = LIBMV_MARKER_STATUS_UNKNOWN;
+	libmv_marker->model_type = LIBMV_MARKER_MODEL_TYPE_POINT;
+	libmv_marker->model_id = 0;
+
+	/* TODO(sergey): We currently don't support reference marker from
+	 * different clip.
+	 */
+	libmv_marker->reference_clip = clip;
+
+	if (track->pattern_match == TRACK

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list