[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56716] trunk/blender: Refine markers position operator
Sergey Sharybin
sergey.vfx at gmail.com
Sun May 12 18:04:14 CEST 2013
Revision: 56716
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56716
Author: nazgul
Date: 2013-05-12 16:04:14 +0000 (Sun, 12 May 2013)
Log Message:
-----------
Refine markers position operator
This operator will run a tracker from previous
keyframe to current frame for all selected markers.
Current markers positions are considering initial
position guess which could be updated by a tracker
for better match.
Useful in cases when feature disappears from the
frame and then appears again. Usage in this case
is the following:
- When feature point re-appeared on frame, manully
place marker on it.
- Use Refine Markers operation (which is in Track
panel) to allow tracker to find a better match.
Depending on direction of tracking use either
Forwards or Backwards refining. It's easy: if
trackign happens forwards, use Refine Frowards,
otherwise use Refine Backwards :)
Modified Paths:
--------------
trunk/blender/release/scripts/startup/bl_ui/space_clip.py
trunk/blender/source/blender/blenkernel/BKE_tracking.h
trunk/blender/source/blender/blenkernel/intern/tracking.c
trunk/blender/source/blender/editors/space_clip/clip_intern.h
trunk/blender/source/blender/editors/space_clip/space_clip.c
trunk/blender/source/blender/editors/space_clip/tracking_ops.c
Modified: trunk/blender/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_clip.py 2013-05-12 16:04:08 UTC (rev 56715)
+++ trunk/blender/release/scripts/startup/bl_ui/space_clip.py 2013-05-12 16:04:14 UTC (rev 56716)
@@ -292,6 +292,14 @@
props.backwards = False
props.sequence = False
+ col = layout.column()
+ col.label(text="Refine:")
+ row = col.row(align=True)
+ props = row.operator("clip.refine_markers", text="Backwards")
+ props.backwards = True
+ props = row.operator("clip.refine_markers", text="Forwards")
+ props.backwards = False
+
col = layout.column(align=True)
props = col.operator("clip.clear_track_path", text="Clear After")
props.action = 'REMAINED'
Modified: trunk/blender/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_tracking.h 2013-05-12 16:04:08 UTC (rev 56715)
+++ trunk/blender/source/blender/blenkernel/BKE_tracking.h 2013-05-12 16:04:14 UTC (rev 56716)
@@ -180,6 +180,7 @@
void BKE_tracking_context_sync(struct MovieTrackingContext *context);
void BKE_tracking_context_sync_user(const struct MovieTrackingContext *context, struct MovieClipUser *user);
int BKE_tracking_context_step(struct MovieTrackingContext *context);
+void BKE_tracking_refine_marker(struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, int backwards);
/* **** Camera solving **** */
int BKE_tracking_reconstruction_check(struct MovieTracking *tracking, struct MovieTrackingObject *object,
Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c 2013-05-12 16:04:08 UTC (rev 56715)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c 2013-05-12 16:04:14 UTC (rev 56716)
@@ -2234,7 +2234,7 @@
typedef struct TrackContext {
#ifdef WITH_LIBMV
/* the reference marker and cutout search area */
- MovieTrackingMarker marker;
+ MovieTrackingMarker reference_marker;
/* keyframed patch. This is the search area */
float *search_area;
@@ -2472,27 +2472,27 @@
*
* Frame is in clip space.
*/
-static ImBuf *tracking_context_get_frame_ibuf(MovieTrackingContext *context, int framenr)
+static ImBuf *tracking_context_get_frame_ibuf(MovieClip *clip, MovieClipUser *user, int clip_flag, int framenr)
{
ImBuf *ibuf;
- MovieClipUser user = context->user;
+ MovieClipUser new_user = *user;
- user.framenr = BKE_movieclip_remap_clip_to_scene_frame(context->clip, framenr);
+ new_user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, framenr);
- ibuf = BKE_movieclip_get_ibuf_flag(context->clip, &user, context->clip_flag, MOVIECLIP_CACHE_SKIP);
+ ibuf = BKE_movieclip_get_ibuf_flag(clip, &new_user, clip_flag, MOVIECLIP_CACHE_SKIP);
return ibuf;
}
/* Get previous keyframed marker. */
-static MovieTrackingMarker *tracking_context_get_keyframed_marker(MovieTrackingContext *context, MovieTrackingTrack *track,
- MovieTrackingMarker *marker)
+static MovieTrackingMarker *tracking_context_get_keyframed_marker(MovieTrackingTrack *track,
+ int curfra, bool backwards)
{
- int a = marker - track->markers;
- MovieTrackingMarker *marker_keyed = marker;
+ MovieTrackingMarker *marker_keyed = BKE_tracking_marker_get(track, curfra);
+ int a = marker_keyed - track->markers;
while (a >= 0 && a < track->markersnr) {
- int next = (context->backwards) ? a + 1 : a - 1;
+ int next = backwards ? a + 1 : a - 1;
bool is_keyframed = false;
MovieTrackingMarker *cur_marker = &track->markers[a];
MovieTrackingMarker *next_marker = NULL;
@@ -2519,35 +2519,36 @@
}
/* Get image buffer for previous marker's keyframe. */
-static ImBuf *tracking_context_get_keyframed_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track,
- MovieTrackingMarker *marker, MovieTrackingMarker **marker_keyed_r)
+static ImBuf *tracking_context_get_keyframed_ibuf(MovieClip *clip, MovieClipUser *user, int clip_flag,
+ MovieTrackingTrack *track, int curfra, bool backwards,
+ MovieTrackingMarker **marker_keyed_r)
{
MovieTrackingMarker *marker_keyed;
int keyed_framenr;
- marker_keyed = tracking_context_get_keyframed_marker(context, track, marker);
+ marker_keyed = tracking_context_get_keyframed_marker(track, curfra, backwards);
keyed_framenr = marker_keyed->framenr;
*marker_keyed_r = marker_keyed;
- return tracking_context_get_frame_ibuf(context, keyed_framenr);
+ return tracking_context_get_frame_ibuf(clip, user, clip_flag, keyed_framenr);
}
/* Get image buffer which si used as referece for track. */
-static ImBuf *tracking_context_get_reference_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track,
- MovieTrackingMarker *marker, int curfra,
- MovieTrackingMarker **marker_keyed)
+static ImBuf *tracking_context_get_reference_ibuf(MovieClip *clip, MovieClipUser *user, int clip_flag,
+ MovieTrackingTrack *track, int curfra, bool backwards,
+ MovieTrackingMarker **reference_marker)
{
ImBuf *ibuf = NULL;
if (track->pattern_match == TRACK_MATCH_KEYFRAME) {
- ibuf = tracking_context_get_keyframed_ibuf(context, track, marker, marker_keyed);
+ ibuf = tracking_context_get_keyframed_ibuf(clip, user, clip_flag, track, curfra, backwards, reference_marker);
}
else {
- ibuf = tracking_context_get_frame_ibuf(context, curfra);
+ ibuf = tracking_context_get_frame_ibuf(clip, user, clip_flag, curfra);
/* use current marker as keyframed position */
- *marker_keyed = marker;
+ *reference_marker = BKE_tracking_marker_get(track, curfra);
}
return ibuf;
@@ -2561,23 +2562,24 @@
MovieTrackingTrack *track, MovieTrackingMarker *marker, int curfra,
int frame_width, int frame_height)
{
- MovieTrackingMarker *marker_keyed = NULL;
+ MovieTrackingMarker *reference_marker = NULL;
ImBuf *reference_ibuf = NULL;
int width, height;
/* calculate patch for keyframed position */
- reference_ibuf = tracking_context_get_reference_ibuf(context, track, marker, curfra, &marker_keyed);
+ reference_ibuf = tracking_context_get_reference_ibuf(context->clip, &context->user, context->clip_flag,
+ track, curfra, context->backwards, &reference_marker);
if (!reference_ibuf)
return false;
- track_context->marker = *marker_keyed;
+ track_context->reference_marker = *reference_marker;
if (track_context->search_area) {
MEM_freeN(track_context->search_area);
}
- track_context->search_area = track_get_search_floatbuf(reference_ibuf, track, marker_keyed, &width, &height);
+ track_context->search_area = track_get_search_floatbuf(reference_ibuf, track, reference_marker, &width, &height);
track_context->search_area_height = height;
track_context->search_area_width = width;
@@ -2593,10 +2595,8 @@
return true;
}
-/* Fill in libmv tracker options structure from a tracking context
- * with settings need to be used to perform track.
- */
-static void tracking_configure_tracker(TrackContext *track_context, MovieTrackingTrack *track,
+/* Fill in libmv tracker options structure with settings need to be used to perform track. */
+static void tracking_configure_tracker(MovieTrackingTrack *track, float *mask,
struct libmv_trackRegionOptions *options)
{
options->motion_model = track->motion_model;
@@ -2610,7 +2610,9 @@
options->sigma = 0.9;
if ((track->algorithm_flag & TRACK_ALGORITHM_FLAG_USE_MASK) != 0)
- options->image1_mask = track_context->mask;
+ options->image1_mask = mask;
+ else
+ options->image1_mask = NULL;
}
/* returns false if marker crossed margin area from frame bounds */
@@ -2703,6 +2705,68 @@
BKE_tracking_marker_insert(track, &new_marker);
}
}
+
+/* Peform tracking from a reference_marker to destination_ibuf.
+ * Uses marker as an initial position guess.
+ *
+ * Returns truth if tracker returned success, puts result
+ * to dst_pixel_x and dst_pixel_y.
+ */
+static bool configure_and_run_tracker(ImBuf *destination_ibuf, MovieTrackingTrack *track,
+ MovieTrackingMarker *reference_marker, MovieTrackingMarker *marker,
+ float *reference_search_area, int reference_search_area_width,
+ int reference_search_area_height, float *mask,
+ double dst_pixel_x[5], double dst_pixel_y[5])
+{
+ /* To convert to the x/y split array format for libmv. */
+ double src_pixel_x[5], src_pixel_y[5];
+
+ /* Settings for the tracker */
+ struct libmv_trackRegionOptions options = {0};
+ struct libmv_trackRegionResult result;
+
+ float *patch_new;
+
+ int new_search_area_width, new_search_area_height;
+ int frame_width, frame_height;
+
+ bool tracked;
+
+ frame_width = destination_ibuf->x;
+ frame_height = destination_ibuf->y;
+
+ /* for now track to the same search area dimension as marker has got for current frame
+ * will make all tracked markers in currently tracked segment have the same search area
+ * size, but it's quite close to what is actually needed
+ */
+ patch_new = track_get_search_floatbuf(destination_ibuf, track, marker,
+ &new_search_area_width, &new_search_area_height);
+
+ /* configure the tracker */
+ tracking_configure_tracker(track, mask, &options);
+
+ /* convert the marker corners and center into pixel coordinates in the search/destination images. */
+ get_marker_coords_for_tracking(frame_width, frame_height, reference_marker, src_pixel_x, src_pixel_y);
+ get_marker_coords_for_tracking(frame_width, frame_height, marker, dst_pixel_x, dst_pixel_y);
+
+ if (patch_new == NULL || reference_search_area == NULL)
+ return false;
+
+ /* run the tracker! */
+ tracked = libmv_trackRegion(&options,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list