Camera tracking integration

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

- Set as Background button will enable displaying background images in 3d space.
- Move options in Display panel to column. Saves some space.
- Camera solving now should deal fine with non-centered principal.
This commit is contained in:
Sergey Sharybin
2011-11-05 14:37:43 +00:00
parent 5a49d05eba
commit dea3b348e5
6 changed files with 67 additions and 42 deletions

View File

@@ -211,6 +211,8 @@ class CLIP_OT_set_viewport_background(Operator):
bgpic.use_camera_clip = False
bgpic.view_axis = 'CAMERA'
space_v3d.show_background_images = True
def execute(self, context):
sc = context.space_data
clip = sc.clip

View File

@@ -363,7 +363,7 @@ class CLIP_PT_tracking_camera(Panel):
col = layout.column(align=True)
col.label(text="Sensor:")
col.prop(clip.tracking.camera, "sensor_width", text="Size")
col.prop(clip.tracking.camera, "sensor_width", text="Width")
col.prop(clip.tracking.camera, "pixel_aspect")
col = layout.column()
@@ -388,36 +388,38 @@ class CLIP_PT_display(Panel):
layout = self.layout
sc = context.space_data
layout.prop(sc, "show_marker_pattern", text="Pattern")
layout.prop(sc, "show_marker_search", text="Search")
layout.prop(sc, "show_pyramid_levels", text="Pyramid")
col = layout.column(align=True)
layout.prop(sc, "show_track_path", text="Path")
row = layout.column()
col.prop(sc, "show_marker_pattern", text="Pattern")
col.prop(sc, "show_marker_search", text="Search")
col.prop(sc, "show_pyramid_levels", text="Pyramid")
col.prop(sc, "show_track_path", text="Path")
row = col.row()
row.active = sc.show_track_path
row.prop(sc, "path_length", text="Length")
layout.prop(sc, "show_disabled", text="Disabled")
layout.prop(sc, "show_bundles", text="Bundles")
col.prop(sc, "show_disabled", text="Disabled")
col.prop(sc, "show_bundles", text="Bundles")
layout.prop(sc, "show_names", text="Names")
layout.prop(sc, "show_tiny_markers", text="Tiny Markers")
col.prop(sc, "show_names", text="Names")
col.prop(sc, "show_tiny_markers", text="Tiny Markers")
layout.prop(sc, "show_grease_pencil", text="Grease Pencil")
layout.prop(sc, "use_mute_footage", text="Mute")
col.prop(sc, "show_grease_pencil", text="Grease Pencil")
col.prop(sc, "use_mute_footage", text="Mute")
if sc.mode == 'DISTORTION':
layout.prop(sc, "show_grid", text="Grid")
layout.prop(sc, "use_manual_calibration")
col.prop(sc, "show_grid", text="Grid")
col.prop(sc, "use_manual_calibration")
elif sc.mode == 'RECONSTRUCTION':
layout.prop(sc, "show_stable", text="Stable")
col.prop(sc, "show_stable", text="Stable")
layout.prop(sc, "lock_selection")
col.prop(sc, "lock_selection")
clip = sc.clip
if clip:
layout.label(text="Display Aspect:")
layout.prop(clip, "display_aspect", text="")
col.label(text="Display Aspect:")
col.prop(clip, "display_aspect", text="")
class CLIP_PT_track_settings(Panel):

View File

@@ -40,8 +40,9 @@ struct MovieTracking;
struct MovieTrackingContext;
struct MovieClipUser;
struct MovieDistortion;
struct Scene;
struct Camera;
struct Object;
struct Scene;
void BKE_tracking_clamp_track(struct MovieTrackingTrack *track, int event);
void BKE_tracking_track_flag(struct MovieTrackingTrack *track, int area, int flag, int clear);
@@ -81,6 +82,9 @@ struct MovieTrackingTrack *BKE_find_track_by_name(struct MovieTracking *tracking
struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);
void BKE_tracking_get_interpolated_camera(struct MovieTracking *tracking, int framenr, float mat[4][4]);
void BKE_tracking_camera_shift(struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
void BKE_tracking_camera_to_blender(struct MovieTracking *tracking, struct Scene *scene, struct Camera *camera, int width, int height);
void BKE_get_tracking_mat(struct Scene *scene, struct Object *ob, 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 nco[2]);

View File

@@ -64,6 +64,7 @@
#include "BKE_anim.h" /* for the curve calculation part */
#include "BKE_armature.h"
#include "BKE_blender.h"
#include "BKE_camera.h"
#include "BKE_constraint.h"
#include "BKE_displist.h"
#include "BKE_deform.h"

View File

@@ -36,6 +36,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_gpencil_types.h"
#include "DNA_camera_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_object_types.h" /* SELECT */
#include "DNA_scene_types.h"
@@ -1497,6 +1498,29 @@ void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4])
unit_m4(mat);
}
void BKE_tracking_camera_shift(MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty)
{
*shiftx= (0.5f*winx-tracking->camera.principal[0]) / winx;
*shifty= (0.5f*winy-tracking->camera.principal[1]) / winx;
}
void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camera *camera, int width, int height)
{
float focal= tracking->camera.focal;
camera->sensor_x= tracking->camera.sensor_width;
camera->sensor_fit= CAMERA_SENSOR_FIT_AUTO;
camera->lens= focal*camera->sensor_x/width;
scene->r.xsch= width*tracking->camera.pixel_aspect;
scene->r.ysch= height;
scene->r.xasp= 1.0f;
scene->r.yasp= 1.0f;
BKE_tracking_camera_shift(tracking, width, height, &camera->shiftx, &camera->shifty);
}
void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4])
{
MovieReconstructedCamera *camera;
@@ -1504,6 +1528,9 @@ void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int wi
float viewfac, pixsize, left, right, bottom, top, clipsta, clipend;
float winmat[4][4];
float ycor= 1.0f/tracking->camera.pixel_aspect;
float shiftx, shifty, winside= MAX2(winx, winy);
BKE_tracking_camera_shift(tracking, winx, winy, &shiftx, &shifty);
clipsta= 0.1f;
clipend= 1000.0f;
@@ -1515,10 +1542,15 @@ void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int wi
pixsize= clipsta/viewfac;
left= -0.5f*(float)winx*pixsize;
bottom= -0.5f*ycor*(float)winy*pixsize;
right= 0.5f*(float)winx*pixsize;
top= 0.5f*ycor*(float)winy*pixsize;
left= -0.5f*(float)winx + shiftx*winside;
bottom= -0.5f*(ycor)*(float)winy + shifty*winside;
right= 0.5f*(float)winx + shiftx*winside;
top= 0.5f*(ycor)*(float)winy + shifty*winside;
left *= pixsize;
right *= pixsize;
bottom *= pixsize;
top *= pixsize;
perspective_m4(winmat, left, right, bottom, top, clipsta, clipend);

View File

@@ -1551,28 +1551,12 @@ static int solve_camera_exec(bContext *C, wmOperator *op)
scene->camera= scene_find_camera(scene);
if(scene->camera) {
float focal= tracking->camera.focal;
/* set blender camera focal length so result would look fine there */
if(focal) {
Camera *camera= (Camera*)scene->camera->data;
Camera *camera= (Camera*)scene->camera->data;
camera->sensor_x= tracking->camera.sensor_width;
camera->lens= focal*camera->sensor_x/width;
BKE_tracking_camera_to_blender(tracking, scene, camera, width, height);
scene->r.xsch= width;
scene->r.ysch= height;
if(tracking->camera.pixel_aspect > 1.0f) {
scene->r.xasp= tracking->camera.pixel_aspect;
scene->r.yasp= 1.0f;
} else {
scene->r.xasp= 1.0f;
scene->r.yasp= 1.0f / tracking->camera.pixel_aspect;
}
WM_event_add_notifier(C, NC_OBJECT, camera);
}
WM_event_add_notifier(C, NC_OBJECT, camera);
}
DAG_id_tag_update(&clip->id, 0);