[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38297] branches/soc-2011-tomato: Camera tracking integration
Sergey Sharybin
g.ulairi at gmail.com
Mon Jul 11 11:04:00 CEST 2011
Revision: 38297
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38297
Author: nazgul
Date: 2011-07-11 09:04:00 +0000 (Mon, 11 Jul 2011)
Log Message:
-----------
Camera tracking integration
===========================
- Changed libmv api to use doubles instead of floats.
No real benefit rather than keeping API uniform.
- Optimized reconstructed camera search. It's optimized for
playback, not random access.
- Added option to show projection of bundles into footage.
To see bundles "Show Bundles" from Display panel should
be enabled. Used very rough limit of 3 px to consider projection
is fine. Colors are still hard-coded. Not sure it could be useful
to make them configurable.
- Added option to mute footage. It could be useful to check
if markers/bundles are moving smoothly.
- Added selector for focal length units.
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/BKE_movieclip.h
branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
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/makesdna/DNA_space_types.h
branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
branches/soc-2011-tomato/source/blender/makesrna/intern/rna_movieclip.c
branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c
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-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp 2011-07-11 09:04:00 UTC (rev 38297)
@@ -331,7 +331,7 @@
return 0;
}
-int libmv_reporojectionCameraForImage(libmv_Reconstruction *reconstruction, int image, float mat[4][4])
+int libmv_reporojectionCameraForImage(libmv_Reconstruction *reconstruction, int image, double mat[4][4])
{
libmv::Camera *camera = ((libmv::Reconstruction *)reconstruction)->CameraForImage(image);
@@ -368,3 +368,20 @@
delete (libmv::Reconstruction *)reconstruction;
}
+/* ************ utils ************ */
+
+void libmv_applyCameraIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ double x, double y, double *x1, double *y1)
+{
+ libmv::CameraIntrinsics intrinsics;
+
+ intrinsics.SetFocalLength(focal_length);
+ intrinsics.set_principal_point(principal_x, principal_y);
+ intrinsics.set_radial_distortion(k1, k2, k3);
+
+ if(focal_length) {
+ /* do a lens undistortion if focal length is non-zero only */
+
+ intrinsics.ApplyIntrinsics(x, y, x1, y1);
+ }
+}
Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h 2011-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h 2011-07-11 09:04:00 UTC (rev 38297)
@@ -58,9 +58,13 @@
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 *reconstruction, int track, double pos[3]);
-int libmv_reporojectionCameraForImage(struct libmv_Reconstruction *reconstruction, int image, float mat[4][4]);
+int libmv_reporojectionCameraForImage(struct libmv_Reconstruction *reconstruction, int image, double mat[4][4]);
void libmv_destroyReconstruction(struct libmv_Reconstruction *reconstruction);
+/* utils */
+void libmv_applyCameraIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ double x, double y, double *x1, double *y1);
+
#ifdef __cplusplus
}
#endif
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-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py 2011-07-11 09:04:00 UTC (rev 38297)
@@ -218,8 +218,12 @@
sc = context.space_data
clip = sc.clip
- layout.prop(clip.tracking.camera, "focal_length")
+ layout.prop(clip.tracking.camera, "sensor_width")
+ row = layout.row()
+ row.prop(clip.tracking.camera, "focal_length")
+ row.prop(clip.tracking.camera, "units", text="")
+
layout.label(text="Principal Point")
layout.prop(clip.tracking.camera, "principal", text="")
@@ -249,6 +253,8 @@
row.prop(sc, "path_length")
layout.prop(sc, "show_tiny_markers")
+ layout.prop(sc, "show_bundles")
+ layout.prop(sc, "use_mute_footage")
class CLIP_PT_test(bpy.types.Panel):
Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h 2011-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h 2011-07-11 09:04:00 UTC (rev 38297)
@@ -48,6 +48,7 @@
struct ImBuf *BKE_movieclip_acquire_ibuf(struct MovieClip *clip, struct MovieClipUser *user);
void BKE_movieclip_acquire_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height);
+void BKE_movieclip_approx_size(struct MovieClip *clip, int *width, int *height);
int BKE_movieclip_has_frame(struct MovieClip *clip, struct MovieClipUser *user);
void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr);
Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h 2011-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h 2011-07-11 09:04:00 UTC (rev 38297)
@@ -75,6 +75,8 @@
struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);
void BKE_get_tracking_mat(struct Scene *scene, float mat[4][4]);
+void BKE_tracking_projection_matrix(struct MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4]);
+void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float width, float height, float nco[2]);
#define TRACK_SELECTED(track) ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT)
#define TRACK_AREA_SELECTED(track, area) ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT))
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c 2011-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c 2011-07-11 09:04:00 UTC (rev 38297)
@@ -214,6 +214,9 @@
clip= alloc_libblock(&G.main->movieclip, ID_MC, name);
+ clip->tracking.camera.sensor_width= 35.0f;
+ clip->tracking.camera.units= CAMERA_UNITS_MM;
+
clip->tracking.settings.frames_limit= 20;
clip->tracking.settings.keyframe1= 1;
clip->tracking.settings.keyframe2= 30;
@@ -281,7 +284,6 @@
ImBuf *ibuf= NULL;
int framenr= user?user->framenr:clip->lastframe;
- clip->lastframe= framenr;
ibuf= get_imbuf_cache(clip, user);
if(!ibuf) {
@@ -294,6 +296,9 @@
put_imbuf_cache(clip, user, ibuf);
}
+ if(ibuf)
+ clip->lastframe= framenr;
+
return ibuf;
}
@@ -325,6 +330,29 @@
IMB_freeImBuf(ibuf);
}
+void BKE_movieclip_approx_size(MovieClip *clip, int *width, int *height)
+{
+ ImBuf *ibuf= BKE_movieclip_acquire_ibuf(clip, NULL);
+
+ if(!ibuf) {
+ MovieClipUser user;
+ user.framenr= 0;
+
+ ibuf= BKE_movieclip_acquire_ibuf(clip, &user);
+ }
+
+ if(ibuf && ibuf->x && ibuf->y) {
+ *width= ibuf->x;
+ *height= ibuf->y;
+ } else {
+ *width= 0;
+ *height= 0;
+ }
+
+ if(ibuf)
+ IMB_freeImBuf(ibuf);
+}
+
/* get segments of cached frames. useful for debugging cache policies */
void BKE_movieclip_get_cache_segments(MovieClip *clip, int *totseg_r, int **points_r)
{
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-07-11 08:43:34 UTC (rev 38296)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-07-11 09:04:00 UTC (rev 38297)
@@ -758,9 +758,16 @@
reconstructed= MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera), "temp reconstructed camera");
for(a= sfra; a<=efra; a++) {
- float mat[4][4];
+ double matd[4][4];
- if(libmv_reporojectionCameraForImage(reconstruction, a, mat)) {
+ if(libmv_reporojectionCameraForImage(reconstruction, a, matd)) {
+ int i, j;
+ float mat[4][4];
+
+ for(i=0; i<4; i++)
+ for(j= 0; j<4; j++)
+ mat[i][j]= matd[i][j];
+
if(!origin_set) {
copy_v3_v3(origin, mat[3]);
origin_set= 1;
@@ -838,11 +845,27 @@
MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(MovieTracking *tracking, int framenr)
{
- int a;
+ MovieTrackingCamera *camera= &tracking->camera;
+ int a= 0, d= 1;
- for (a= 0; a<tracking->camera.reconnr; a++ ) {
- if(tracking->camera.reconstructed[a].framenr==framenr)
- return &tracking->camera.reconstructed[a];
+ if(!camera->reconnr)
+ return NULL;
+
+ if(camera->last_camera<camera->reconnr)
+ a= camera->last_camera;
+
+ if(camera->reconstructed[a].framenr>=framenr)
+ d= -1;
+
+ while(a>=0 && a<camera->reconnr) {
+ if(camera->reconstructed[a].framenr==framenr) {
+ camera->last_camera= a;
+ return &camera->reconstructed[a];
+
+ break;
+ }
+
+ a+= d;
}
return NULL;
@@ -862,3 +885,56 @@
copy_m4_m4(mat, obmat);
}
+
+void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4])
+{
+ MovieReconstructedCamera *camera;
+ float lens= tracking->camera.focal*32.0f/(float)winx;
+ float viewfac, pixsize, left, right, bottom, top, clipsta, clipend;
+ float winmat[4][4];
+
+ clipsta= 0.1f;
+ clipend= 1000.0f;
+
+ if(winx >= winy)
+ viewfac= (lens*winx)/32.0f;
+ else
+ viewfac= (lens*winy)/32.0f;
+
+ pixsize= clipsta/viewfac;
+
+ left= -0.5f*(float)winx*pixsize;
+ bottom= -0.5f*(float)winy*pixsize;
+ right= 0.5f*(float)winx*pixsize;
+ top= 0.5f*(float)winy*pixsize;
+
+ perspective_m4(winmat, left, right, bottom, top, clipsta, clipend);
+
+ camera= BKE_tracking_get_reconstructed_camera(tracking, framenr);
+ if(camera) {
+ float imat[4][4];
+
+ invert_m4_m4(imat, camera->mat);
+ mul_m4_m4m4(mat, imat, winmat);
+ } else copy_m4_m4(mat, winmat);
+}
+
+void BKE_tracking_apply_intrinsics(MovieTracking *tracking, float co[2], float width, float height, float nco[2])
+{
+ MovieTrackingCamera *camera= &tracking->camera;
+
+#ifdef WITH_LIBMV
+ double x= nco[0], y= nco[1];
+
+ /* normalize coords */
+ x= (co[0]-camera->principal[0]) / camera->focal;
+ y= (co[1]-camera->principal[1]) / camera->focal;
+
+ libmv_applyCameraIntrinsics(camera->focal, camera->principal[0], camera->principal[1],
+ camera->k1, camera->k2, camera->k3, x, y, &x, &y);
+
+ /* result is in image coords already */
+ nco[0]= x;
+ nco[1]= y;
+#endif
+}
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-07-11 08:43:34 UTC (rev 38296)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list