Camera tracking integration: cleanup and finish some parts of recent commit
- Replace set of booleans with menu, so now you'll simply be unable to choose unsupported refine combination - Some internal code cleanup and minor refactor
This commit is contained in:
parent
d4fec9f19f
commit
55d0cb04aa
|
@ -397,10 +397,10 @@ libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *tracks, int keyfra
|
|||
|
||||
libmv::Tracks normalized_tracks(markers);
|
||||
|
||||
printf("frames to init from: %d, %d\n", keyframe1, keyframe2);
|
||||
// printf("frames to init from: %d, %d\n", keyframe1, keyframe2);
|
||||
libmv::vector<libmv::Marker> keyframe_markers =
|
||||
normalized_tracks.MarkersForTracksInBothImages(keyframe1, keyframe2);
|
||||
printf("number of markers for init: %d\n", keyframe_markers.size());
|
||||
// printf("number of markers for init: %d\n", keyframe_markers.size());
|
||||
|
||||
libmv::EuclideanReconstructTwoFrames(keyframe_markers, reconstruction);
|
||||
libmv::EuclideanBundle(normalized_tracks, reconstruction);
|
||||
|
|
|
@ -157,15 +157,14 @@ class CLIP_PT_tools_solving(Panel):
|
|||
col.operator("clip.solve_camera")
|
||||
col.operator("clip.clear_solution")
|
||||
|
||||
layout.prop(settings, "refine_focal_length")
|
||||
layout.prop(settings, "refine_principal_point")
|
||||
layout.prop(settings, "refine_radial_distortion_k1")
|
||||
layout.prop(settings, "refine_radial_distortion_k2")
|
||||
|
||||
col = layout.column(align=True)
|
||||
col.prop(settings, "keyframe_a")
|
||||
col.prop(settings, "keyframe_b")
|
||||
|
||||
col = layout.column(align=True)
|
||||
col.label(text="Refine:")
|
||||
col.prop(settings, "refine_intrinsics", text="")
|
||||
|
||||
|
||||
class CLIP_PT_tools_cleanup(Panel):
|
||||
bl_space_type = 'CLIP_EDITOR'
|
||||
|
|
|
@ -91,6 +91,8 @@ void BKE_tracking_sync_user(struct MovieClipUser *user, struct MovieTrackingCont
|
|||
int BKE_tracking_next(struct MovieTrackingContext *context);
|
||||
|
||||
/* Camera solving */
|
||||
int BKE_tracking_can_solve(struct MovieTracking *tracking, char *error_msg, int error_size);
|
||||
|
||||
float BKE_tracking_solve_reconstruction(struct MovieTracking *tracking, int width, int height);
|
||||
|
||||
struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "BLI_listbase.h"
|
||||
#include "BLI_ghash.h"
|
||||
#include "BLI_path_util.h"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_tracking.h"
|
||||
|
@ -1257,7 +1258,28 @@ static struct libmv_Tracks *create_libmv_tracks(MovieTracking *tracking, int wid
|
|||
return tracks;
|
||||
}
|
||||
|
||||
static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
|
||||
static void retrieve_libmv_reconstruct_intrinscis(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
|
||||
{
|
||||
struct libmv_CameraIntrinsics *libmv_intrinsics = libmv_ReconstructionExtractIntrinsics(libmv_reconstruction);
|
||||
|
||||
float aspy= 1.0f/tracking->camera.pixel_aspect;
|
||||
|
||||
double focal_length, principal_x, principal_y, k1, k2, k3;
|
||||
int width, height;
|
||||
|
||||
libmv_CameraIntrinsicsExtract(libmv_intrinsics, &focal_length, &principal_x, &principal_y,
|
||||
&k1, &k2, &k3, &width, &height);
|
||||
|
||||
tracking->camera.focal= focal_length;
|
||||
tracking->camera.principal[0]= principal_x;
|
||||
|
||||
/* todo: verify divide by aspy is correct */
|
||||
tracking->camera.principal[1]= principal_y / aspy;
|
||||
tracking->camera.k1= k1;
|
||||
tracking->camera.k2= k2;
|
||||
}
|
||||
|
||||
static int retrieve_libmv_reconstruct_tracks(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
|
||||
{
|
||||
int tracknr= 0;
|
||||
int sfra= INT_MAX, efra= INT_MIN, a, origin_set= 0;
|
||||
|
@ -1267,24 +1289,6 @@ static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reco
|
|||
float origin[3]= {0.0f, 0.0f, 0.0f};
|
||||
int ok= 1;
|
||||
|
||||
/* take the intrinscis back from libmv */
|
||||
{
|
||||
struct libmv_CameraIntrinsics *libmv_intrinsics = libmv_ReconstructionExtractIntrinsics(libmv_reconstruction);
|
||||
|
||||
float aspy= 1.0f/tracking->camera.pixel_aspect;
|
||||
|
||||
double focal_length, principal_x, principal_y, k1, k2, k3;
|
||||
int width, height;
|
||||
libmv_CameraIntrinsicsExtract(libmv_intrinsics, &focal_length, &principal_x, &principal_y,
|
||||
&k1, &k2, &k3, &width, &height);
|
||||
tracking->camera.focal = focal_length;
|
||||
tracking->camera.principal[0] = principal_x;
|
||||
/* todo: verify divide by aspy is correct */
|
||||
tracking->camera.principal[1] = principal_y / aspy;
|
||||
tracking->camera.k1 = k1;
|
||||
tracking->camera.k2 = k2;
|
||||
}
|
||||
|
||||
track= tracking->tracks.first;
|
||||
while(track) {
|
||||
double pos[3];
|
||||
|
@ -1369,19 +1373,79 @@ static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reco
|
|||
return ok;
|
||||
}
|
||||
|
||||
static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
|
||||
{
|
||||
/* take the intrinscis back from libmv */
|
||||
retrieve_libmv_reconstruct_intrinscis(tracking, libmv_reconstruction);
|
||||
|
||||
return retrieve_libmv_reconstruct_tracks(tracking, libmv_reconstruction);
|
||||
}
|
||||
|
||||
static int get_refine_intrinsics_flags(MovieTracking *tracking)
|
||||
{
|
||||
int refine= tracking->settings.refine_camera_intrinsics;
|
||||
int flags= 0;
|
||||
|
||||
if(refine&REFINE_FOCAL_LENGTH)
|
||||
flags|= LIBMV_REFINE_FOCAL_LENGTH;
|
||||
|
||||
if(refine&REFINE_PRINCIPAL_POINT)
|
||||
flags|= LIBMV_REFINE_PRINCIPAL_POINT;
|
||||
|
||||
if(refine&REFINE_RADIAL_DISTORTION_K1)
|
||||
flags|= REFINE_RADIAL_DISTORTION_K1;
|
||||
|
||||
if(refine&REFINE_RADIAL_DISTORTION_K2)
|
||||
flags|= REFINE_RADIAL_DISTORTION_K2;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
static int count_tracks_on_both_keyframes(MovieTracking *tracking)
|
||||
{
|
||||
int tot= 0;
|
||||
int frame1= tracking->settings.keyframe1, frame2= tracking->settings.keyframe2;
|
||||
MovieTrackingTrack *track;
|
||||
|
||||
track= tracking->tracks.first;
|
||||
while(track) {
|
||||
if(BKE_tracking_has_marker(track, frame1))
|
||||
if(BKE_tracking_has_marker(track, frame2))
|
||||
tot++;
|
||||
|
||||
track= track->next;
|
||||
}
|
||||
|
||||
return tot;
|
||||
}
|
||||
#endif
|
||||
|
||||
int BKE_tracking_can_solve(MovieTracking *tracking, char *error_msg, int error_size)
|
||||
{
|
||||
#if WITH_LIBMV
|
||||
if(count_tracks_on_both_keyframes(tracking)<8) {
|
||||
BLI_strncpy(error_msg, "At least 8 tracks on both of keyframes are needed for reconstruction", error_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
#else
|
||||
BLI_strncpy(error_msg, "Blender is compiled without motion tracking library", error_size);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
float BKE_tracking_solve_reconstruction(MovieTracking *tracking, int width, int height)
|
||||
{
|
||||
#if WITH_LIBMV
|
||||
{
|
||||
MovieTrackingCamera *camera= &tracking->camera;
|
||||
float aspy= 1.0f/tracking->camera.pixel_aspect;
|
||||
|
||||
struct libmv_Tracks *tracks= create_libmv_tracks(tracking, width, height*aspy);
|
||||
struct libmv_Reconstruction *reconstruction = libmv_solveReconstruction(tracks,
|
||||
tracking->settings.keyframe1, tracking->settings.keyframe2,
|
||||
tracking->settings.refine_camera_intrinsics,
|
||||
get_refine_intrinsics_flags(tracking),
|
||||
camera->focal,
|
||||
camera->principal[0], camera->principal[1]*aspy,
|
||||
camera->k1, camera->k2, camera->k3);
|
||||
|
|
|
@ -1504,24 +1504,6 @@ void CLIP_OT_track_markers(wmOperatorType *ot)
|
|||
|
||||
/********************** solve camera operator *********************/
|
||||
|
||||
static int check_solve_track_count(MovieTracking *tracking)
|
||||
{
|
||||
int tot= 0;
|
||||
int frame1= tracking->settings.keyframe1, frame2= tracking->settings.keyframe2;
|
||||
MovieTrackingTrack *track;
|
||||
|
||||
track= tracking->tracks.first;
|
||||
while(track) {
|
||||
if(BKE_tracking_has_marker(track, frame1))
|
||||
if(BKE_tracking_has_marker(track, frame2))
|
||||
tot++;
|
||||
|
||||
track= track->next;
|
||||
}
|
||||
|
||||
return tot>=8;
|
||||
}
|
||||
|
||||
static int solve_camera_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceClip *sc= CTX_wm_space_clip(C);
|
||||
|
@ -1530,18 +1512,13 @@ static int solve_camera_exec(bContext *C, wmOperator *op)
|
|||
MovieTracking *tracking= &clip->tracking;
|
||||
int width, height;
|
||||
float error;
|
||||
char error_msg[255];
|
||||
|
||||
if(!BKE_tracking_can_solve(tracking, error_msg, sizeof(error_msg))) {
|
||||
BKE_report(op->reports, RPT_ERROR, error_msg);
|
||||
|
||||
if(!check_solve_track_count(tracking)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "At least 8 tracks on both of keyframes are needed for reconstruction");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
/* XXX sergey, please fix this. it's not obvious to me that it is not
|
||||
* an encapsulation violation to call the libmv c api from here. */
|
||||
/*
|
||||
if(!libmv_refineParametersAreValid(tracking->settings.refine_camera_intrinsics)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Invalid combination for intrinsic refinement");
|
||||
return OPERATOR_CANCELLED;
|
||||
}*/
|
||||
|
||||
/* could fail if footage uses images with different sizes */
|
||||
BKE_movieclip_get_size(clip, NULL, &width, &height);
|
||||
|
|
|
@ -124,8 +124,9 @@ typedef struct MovieTrackingSettings {
|
|||
int keyframe1, keyframe2; /* two keyframes for reconstrution initialization */
|
||||
|
||||
/* ** which camera intrinsics to refine. uses on the REFINE_* flags */
|
||||
int refine_camera_intrinsics;
|
||||
char pad2[4];
|
||||
short refine_camera_intrinsics;
|
||||
|
||||
char pad2[6];
|
||||
|
||||
/* ** tool settings ** */
|
||||
|
||||
|
@ -186,12 +187,6 @@ enum {
|
|||
#define MARKER_TRACKED (1<<1)
|
||||
#define MARKER_GRAPH_SEL (1<<2)
|
||||
|
||||
/* MovieTrackingSettings->refine_camera_intrinsics */
|
||||
#define REFINE_FOCAL_LENGTH (1<<0)
|
||||
#define REFINE_PRINCIPAL_POINT (1<<1)
|
||||
#define REFINE_RADIAL_DISTORTION_K1 (1<<2)
|
||||
#define REFINE_RADIAL_DISTORTION_K2 (1<<4)
|
||||
|
||||
/* MovieTrackingTrack->flag */
|
||||
#define TRACK_HAS_BUNDLE (1<<1)
|
||||
#define TRACK_DISABLE_RED (1<<2)
|
||||
|
@ -213,6 +208,12 @@ enum {
|
|||
#define TRACKING_SPEED_QUARTER 4
|
||||
#define TRACKING_SPEED_DOUBLE 5
|
||||
|
||||
/* MovieTrackingSettings->refine_camera_intrinsics */
|
||||
#define REFINE_FOCAL_LENGTH (1<<0)
|
||||
#define REFINE_PRINCIPAL_POINT (1<<1)
|
||||
#define REFINE_RADIAL_DISTORTION_K1 (1<<2)
|
||||
#define REFINE_RADIAL_DISTORTION_K2 (1<<4)
|
||||
|
||||
/* MovieTrackingStrabilization->flag */
|
||||
#define TRACKING_2D_STABILIZATION (1<<0)
|
||||
#define TRACKING_AUTOSCALE (1<<1)
|
||||
|
|
|
@ -236,6 +236,23 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
|
|||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static EnumPropertyItem refine_items[] = {
|
||||
{0, "NONE", 0, "Nothing", "Do not refine camera intrinsics"},
|
||||
{REFINE_FOCAL_LENGTH, "FOCAL_LENGTH", 0, "Focal Length", "Refine focal length"},
|
||||
{REFINE_FOCAL_LENGTH|
|
||||
REFINE_PRINCIPAL_POINT, "FOCAL_LENGTH_PRINCIPAL_POINT", 0, "Focal Length, Principal Point", "Refine focal length and principal point"},
|
||||
{REFINE_FOCAL_LENGTH|
|
||||
REFINE_PRINCIPAL_POINT|
|
||||
REFINE_RADIAL_DISTORTION_K1|
|
||||
REFINE_RADIAL_DISTORTION_K2,
|
||||
"FOCAL_LENGTH_PRINCIPAL_POINT_RADIAL_K1_K2", 0, "Focal Length, Principal Point, K1, K2", "Refine focal length, principal point and radial distortion K1 and K2"},
|
||||
{REFINE_FOCAL_LENGTH|
|
||||
REFINE_RADIAL_DISTORTION_K1|
|
||||
REFINE_RADIAL_DISTORTION_K2, "FOCAL_LENGTH_RADIAL_K1_K2", 0, "Focal length, K1. K2", "Refine focal length and radial distortion K1 and K2"},
|
||||
{REFINE_FOCAL_LENGTH|REFINE_RADIAL_DISTORTION_K1, "FOCAL_LENGTH_RADIAL_K1", 0, "Focal length, K1", "Refine focal length and radial distortion K1"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
srna= RNA_def_struct(brna, "MovieTrackingSettings", NULL);
|
||||
RNA_def_struct_ui_text(srna, "Movie tracking settings", "Match moving settings");
|
||||
|
||||
|
@ -278,25 +295,12 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
|
|||
RNA_def_property_int_sdna(prop, NULL, "keyframe2");
|
||||
RNA_def_property_ui_text(prop, "Keyframe B", "Second keyframe used for reconstruction initialization");
|
||||
|
||||
/* intrinsics refinement during bundle adjustment - focal length */
|
||||
prop= RNA_def_property(srna, "refine_focal_length", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "refine_camera_intrinsics", REFINE_FOCAL_LENGTH);
|
||||
RNA_def_property_ui_text(prop, "Focal length", "Refine focal length during solving");
|
||||
|
||||
/* intrinsics refinement during bundle adjustment - principal point */
|
||||
prop= RNA_def_property(srna, "refine_principal_point", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "refine_camera_intrinsics", REFINE_PRINCIPAL_POINT);
|
||||
RNA_def_property_ui_text(prop, "Principal Point", "Refine principal point during solving");
|
||||
|
||||
/* intrinsics refinement during bundle adjustment - radial distortion k1 */
|
||||
prop= RNA_def_property(srna, "refine_radial_distortion_k1", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "refine_camera_intrinsics", REFINE_RADIAL_DISTORTION_K1);
|
||||
RNA_def_property_ui_text(prop, "Radial Distortion K1", "Refine K1 radial distortion parameter during solving");
|
||||
|
||||
/* intrinsics refinement during bundle adjustment - radial distortion k2 */
|
||||
prop= RNA_def_property(srna, "refine_radial_distortion_k2", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "refine_camera_intrinsics", REFINE_RADIAL_DISTORTION_K2);
|
||||
RNA_def_property_ui_text(prop, "Radial Distortion K2", "Refine K2 radial distortion parameter during solving");
|
||||
/* intrinsics refinement during bundle adjustment */
|
||||
prop= RNA_def_property(srna, "refine_intrinsics", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "refine_camera_intrinsics");
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_enum_items(prop, refine_items);
|
||||
RNA_def_property_ui_text(prop, "Refine", "Refine intrinsics during camera solving");
|
||||
|
||||
/* tool settings */
|
||||
|
||||
|
|
Loading…
Reference in New Issue