[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39026] branches/soc-2011-tomato: Camera tracking integration
Sergey Sharybin
g.ulairi at gmail.com
Thu Aug 4 17:40:29 CEST 2011
Revision: 39026
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39026
Author: nazgul
Date: 2011-08-04 15:40:28 +0000 (Thu, 04 Aug 2011)
Log Message:
-----------
Camera tracking integration
===========================
- Added function to calculate per-track average error.
Made this in libmv c-api, probably should be ported
to libmv pipeline.
- MovieTrackingTrack now holds average reprojection error
which is displayed in Active Track panel and information
text in clip editor (if displaying of names are enabled).
- Make "Clean Tracks" take average error on account.
Modified Paths:
--------------
branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
branches/soc-2011-tomato/extern/libmv/libmv-capi.h
branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c
Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp 2011-08-04 15:40:28 UTC (rev 39026)
@@ -67,6 +67,11 @@
typedef struct libmv_Reconstruction {
libmv::Reconstruction reconstruction;
+
+ /* used for per-track average error calculation after reconstruction */
+ libmv::Tracks tracks;
+ libmv::CameraIntrinsics intrinsics;
+
double error;
} libmv_Reconstruction;
@@ -326,18 +331,18 @@
{
/* Invert the camera intrinsics. */
libmv::vector<libmv::Marker> markers = ((libmv::Tracks*)tracks)->AllMarkers();
- libmv::CameraIntrinsics intrinsics;
libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction();
libmv::Reconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+ libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
- intrinsics.SetFocalLength(focal_length, focal_length);
- intrinsics.SetPrincipalPoint(principal_x, principal_y);
- intrinsics.SetRadialDistortion(k1, k2, k3);
+ intrinsics->SetFocalLength(focal_length, focal_length);
+ intrinsics->SetPrincipalPoint(principal_x, principal_y);
+ intrinsics->SetRadialDistortion(k1, k2, k3);
if(focal_length) {
/* do a lens undistortion if focal length is non-zero only */
for (int i = 0; i < markers.size(); ++i) {
- intrinsics.InvertIntrinsics(markers[i].x,
+ intrinsics->InvertIntrinsics(markers[i].x,
markers[i].y,
&(markers[i].x),
&(markers[i].y));
@@ -352,8 +357,10 @@
libmv::ReconstructTwoFrames(keyframe_markers, reconstruction);
libmv::Bundle(normalized_tracks, reconstruction);
libmv::CompleteReconstruction(normalized_tracks, reconstruction);
- libmv_reconstruction->error = libmv::ReprojectionError(*(libmv::Tracks *)tracks, *reconstruction, intrinsics);
+ libmv_reconstruction->tracks = *(libmv::Tracks *)tracks;
+ libmv_reconstruction->error = libmv::ReprojectionError(*(libmv::Tracks *)tracks, *reconstruction, *intrinsics);
+
return (libmv_Reconstruction *)libmv_reconstruction;
}
@@ -373,6 +380,49 @@
return 0;
}
+static libmv::Marker ProjectMarker(const libmv::Point &point, const libmv::Camera &camera,
+ const libmv::CameraIntrinsics &intrinsics) {
+ libmv::Vec3 projected = camera.R * point.X + camera.t;
+ projected /= projected(2);
+
+ libmv::Marker reprojected_marker;
+ intrinsics.ApplyIntrinsics(projected(0), projected(1), &reprojected_marker.x, &reprojected_marker.y);
+
+ reprojected_marker.image = camera.image;
+ reprojected_marker.track = point.track;
+
+ return reprojected_marker;
+}
+
+double libmv_reporojectionErrorForTrack(libmv_Reconstruction *libmv_reconstruction, int track)
+{
+ libmv::Reconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+ libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
+ libmv::vector<libmv::Marker> markers = libmv_reconstruction->tracks.MarkersForTrack(track);
+
+ int num_reprojected = 0;
+ double total_error = 0.0;
+
+ for (int i = 0; i < markers.size(); ++i) {
+ const libmv::Camera *camera = reconstruction->CameraForImage(markers[i].image);
+ const libmv::Point *point = reconstruction->PointForTrack(markers[i].track);
+
+ if (!camera || !point) {
+ continue;
+ }
+
+ num_reprojected++;
+
+ libmv::Marker reprojected_marker = ProjectMarker(*point, *camera, *intrinsics);
+ double ex = reprojected_marker.x - markers[i].x;
+ double ey = reprojected_marker.y - markers[i].y;
+
+ total_error += sqrt(ex*ex + ey*ey);
+ }
+
+ return total_error / num_reprojected;
+}
+
int libmv_reporojectionCameraForImage(libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4])
{
libmv::Reconstruction *reconstruction = &libmv_reconstruction->reconstruction;
Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h 2011-08-04 15:40:28 UTC (rev 39026)
@@ -59,6 +59,7 @@
struct libmv_Reconstruction *libmv_solveReconstruction(struct libmv_Tracks *tracks, int keyframe1, int keyframe2,
double focal_length, double principal_x, double principal_y, double k1, double k2, double k3);
int libmv_reporojectionPointForTrack(struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]);
+double libmv_reporojectionErrorForTrack(struct libmv_Reconstruction *libmv_reconstruction, int track);
int libmv_reporojectionCameraForImage(struct libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4]);
double libmv_reprojectionError(struct libmv_Reconstruction *libmv_reconstruction);
void libmv_destroyReconstruction(struct libmv_Reconstruction *libmv_reconstruction);
Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py 2011-08-04 15:40:28 UTC (rev 39026)
@@ -239,7 +239,11 @@
row.prop(act_track, "use_green_channel", text="Green")
row.prop(act_track, "use_blue_channel", text="Blue")
+ if act_track.has_bundle:
+ label_text = "Average Error: %.4f" % (act_track.average_error)
+ layout.label(text=label_text)
+
class CLIP_PT_track_settings(bpy.types.Panel):
bl_space_type = 'CLIP_EDITOR'
bl_region_type = 'UI'
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-08-04 15:40:28 UTC (rev 39026)
@@ -916,6 +916,7 @@
track->bundle_pos[2]= pos[2];
track->flag|= TRACK_HAS_BUNDLE;
+ track->error= libmv_reporojectionErrorForTrack(libmv_reconstruction, tracknr);
} else {
track->flag&= ~TRACK_HAS_BUNDLE;
ok= 0;
Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c 2011-08-04 15:40:28 UTC (rev 39026)
@@ -719,9 +719,16 @@
BLI_snprintf(str, sizeof(str), "%s", track->name);
UI_DrawString(x, y, str);
+ y-= 12.f*UI_DPI_FAC;
+ if(track->flag&TRACK_HAS_BUNDLE) {
+ BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error);
+ UI_DrawString(x, y, str);
+ y-= 12.f*UI_DPI_FAC;
+ }
+
if(track->flag&TRACK_LOCKED) {
- UI_DrawString(x, y-12.f*UI_DPI_FAC, "locked");
+ UI_DrawString(x, y, "locked");
}
}
Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c 2011-08-04 15:40:28 UTC (rev 39026)
@@ -2702,17 +2702,25 @@
MovieTrackingTrack *track, *next, *sel_track;
int frames= RNA_int_get(op->ptr, "frames");
int action= RNA_enum_get(op->ptr, "action");
+ float error= RNA_float_get(op->ptr, "error");
int sel_type;
BKE_movieclip_last_selection(clip, &sel_type, (void**)&sel_track);
if(sel_type!=MCLIP_SEL_TRACK)
sel_track= NULL;
+ if(error && action==2)
+ action= 1;
+
track= tracking->tracks.first;
while(track) {
+ int ok= 1;
next= track->next;
- if(!is_track_clean(track, frames, action==2)) {
+ ok&= is_track_clean(track, frames, action==2);
+ ok&= error == 0.f || (track->flag&TRACK_HAS_BUNDLE)==0 || track->error < error;
+
+ if(!ok) {
if(action==0) { /* select */
BKE_tracking_track_flag(track, TRACK_AREA_ALL, SELECT, 0);
}
@@ -2764,6 +2772,7 @@
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
- RNA_def_int(ot->srna, "frames", 0, 0, INT_MAX, "Tracked Frames", "Affect on tracks which are aracked less than specified amount of frames.", 0, INT_MAX);
+ RNA_def_int(ot->srna, "frames", 0, 0, INT_MAX, "Tracked Frames", "Affect on tracks which are tracked less than specified amount of frames.", 0, INT_MAX);
+ RNA_def_float(ot->srna, "error", 0.0f, 0.f, FLT_MAX, "Reprojection Error", "Affect on tracks with have got larger reprojection error.", 0.f, 100.0f);
RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Cleanup action to execute");
}
Modified: branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h 2011-08-04 15:40:28 UTC (rev 39026)
@@ -81,17 +81,17 @@
float search_min[2], search_max[2]; /* positions of left-bottom and right-top corners of search area (in unified 0..1 space) */
float offset[2]; /* offset to "parenting" point */
- int pad;
-
/* ** track ** */
int markersnr; /* count of markers in track */
int last_marker; /* most recently used marker */
- int pad2;
MovieTrackingMarker *markers; /* markers in track */
- /* ** bundle ** */
- float bundle_pos[3];
+ /* ** reconstruction data ** */
+ float bundle_pos[3]; /* reconstructed position */
+ float error; /* average track reprojection error */
+ int pad;
+
/* ** UI editing ** */
int flag, pat_flag, search_flag; /* flags (selection, ...) */
short transflag; /* transform flags */
Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c 2011-08-04 14:39:37 UTC (rev 39025)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c 2011-08-04 15:40:28 UTC (rev 39026)
@@ -456,6 +456,12 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list