Camera tracking integration

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

- Changed 3D viewport reconstruction settings to more usable defaults
- Some code clean-up
- Option to place markers for detected features across the whole frame,
  inside grease pencil areas or outside of grease pencil areas.
This commit is contained in:
Sergey Sharybin
2011-10-31 14:01:40 +00:00
parent 6de5c38e73
commit 8e42433f02
9 changed files with 69 additions and 72 deletions

View File

@@ -87,10 +87,12 @@ void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2],
void BKE_tracking_invert_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);
void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ImBuf *imbuf,
int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer);
int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer,
int place_outside_layer);
void BKE_tracking_detect_moravec(struct MovieTracking *tracking, struct ImBuf *imbuf,
int framenr, int margin, int count, int min_distance, struct bGPDlayer *layer);
int framenr, int margin, int count, int min_distance, struct bGPDlayer *layer,
int place_outside_layer);
struct MovieTrackingTrack *BKE_tracking_indexed_bundle(struct MovieTracking *tracking, int bundlenr);

View File

@@ -1609,7 +1609,7 @@ static int point_in_layer(bGPDlayer *layer, float x, float y)
}
static void retrieve_libmv_features(MovieTracking *tracking, struct libmv_Features *features,
int framenr, int width, int height, bGPDlayer *layer)
int framenr, int width, int height, bGPDlayer *layer, int place_outside_layer)
{
#ifdef WITH_LIBMV
int a;
@@ -1627,7 +1627,7 @@ static void retrieve_libmv_features(MovieTracking *tracking, struct libmv_Featur
yu= y/height;
if(layer)
ok= point_in_layer(layer, xu, yu);
ok= point_in_layer(layer, xu, yu)!=place_outside_layer;
if(ok) {
track= BKE_tracking_add_track(tracking, xu, yu, framenr, width, height);
@@ -1640,7 +1640,8 @@ static void retrieve_libmv_features(MovieTracking *tracking, struct libmv_Featur
}
void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf,
int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer)
int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer,
int place_outside_layer)
{
#ifdef WITH_LIBMV
struct libmv_Features *features;
@@ -1650,14 +1651,14 @@ void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf,
MEM_freeN(pixels);
retrieve_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, layer);
retrieve_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, layer, place_outside_layer);
libmv_destroyFeatures(features);
#endif
}
void BKE_tracking_detect_moravec(MovieTracking *tracking, ImBuf *ibuf,
int framenr, int margin, int count, int min_distance, bGPDlayer *layer)
int framenr, int margin, int count, int min_distance, bGPDlayer *layer, int place_outside_layer)
{
#ifdef WITH_LIBMV
struct libmv_Features *features;
@@ -1667,7 +1668,7 @@ void BKE_tracking_detect_moravec(MovieTracking *tracking, ImBuf *ibuf,
MEM_freeN(pixels);
retrieve_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, layer);
retrieve_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, layer, place_outside_layer);
libmv_destroyFeatures(features);
#endif

View File

@@ -12343,12 +12343,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
if(sl->spacetype==SPACE_VIEW3D) {
View3D *v3d= (View3D *)sl;
if(v3d->bundle_size==0.0f) {
v3d->bundle_size= 0.1f;
v3d->bundle_size= 0.2f;
v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
}
if(v3d->bundle_drawtype==0)
v3d->bundle_drawtype= OB_EMPTY_SPHERE;
v3d->bundle_drawtype= OB_PLAINAXES;
}
else if(sl->spacetype==SPACE_CLIP) {
SpaceClip *sc= (SpaceClip *)sl;

View File

@@ -71,14 +71,31 @@
/*********************** main area drawing *************************/
void clip_draw_curfra_label(SpaceClip *sc, float x, float y)
{
uiStyle *style= UI_GetStyle();
int fontid= style->widget.uifont_id;
char str[32];
float fontsize, fontwidth;
/* frame number */
BLF_size(fontid, 11.0f, U.dpi);
BLI_snprintf(str, sizeof(str), "%d", sc->user.framenr);
fontsize= BLF_height(fontid, str);
fontwidth= BLF_width(fontid, str);
glRecti(x, y, x+fontwidth+6, y+fontsize+4);
UI_ThemeColor(TH_TEXT);
BLF_position(fontid, x+2.0f, y+2.0f, 0.0f);
BLF_draw(fontid, str, strlen(str));
}
static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Scene *scene)
{
float x;
int *points, totseg, i, a;
float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1), fontsize, fontwidth;
uiStyle *style= UI_GetStyle();
int fontid= style->widget.uifont_id;
char str[32];
float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1);
glEnable(GL_BLEND);
@@ -169,17 +186,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
UI_ThemeColor(TH_CFRAME);
glRecti(x, 0, x+framelen, 8);
/* frame number */
BLF_size(fontid, 11.0f, U.dpi);
BLI_snprintf(str, sizeof(str), "%d", sc->user.framenr);
fontsize= BLF_height(fontid, str);
fontwidth= BLF_width(fontid, str);
glRecti(x, 8, x+fontwidth+6, 12+fontsize);
UI_ThemeColor(TH_TEXT);
BLF_position(fontid, x+2.0f, 10.0f, 0.0f);
BLF_draw(fontid, str, strlen(str));
clip_draw_curfra_label(sc, x, 8.0f);
}
static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar)
@@ -1240,7 +1247,7 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
glPopMatrix();
}
void draw_clip_main(SpaceClip *sc, ARegion *ar, Scene *scene)
void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene)
{
MovieClip *clip= ED_space_clip(sc);
ImBuf *ibuf;
@@ -1288,7 +1295,7 @@ void draw_clip_main(SpaceClip *sc, ARegion *ar, Scene *scene)
}
/* draw grease pencil */
void draw_clip_grease_pencil(bContext *C, int onlyv2d)
void clip_draw_grease_pencil(bContext *C, int onlyv2d)
{
SpaceClip *sc= CTX_wm_space_clip(C);
MovieClip *clip= ED_space_clip(sc);

View File

@@ -89,11 +89,7 @@ static void draw_curve_knot(float x, float y, float xscale, float yscale, float
static void draw_graph_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
{
View2D *v2d= &ar->v2d;
uiStyle *style= UI_GetStyle();
int fontid= style->widget.uifont_id, fontsize;
float xscale, yscale, x, y;
char str[32];
short slen;
float xscale, yscale;
float vec[2];
/* Draw a light green line to indicate current frame */
@@ -118,23 +114,7 @@ static void draw_graph_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
UI_view2d_getscale(v2d, &xscale, &yscale);
glScalef(1.0f/xscale, 1.0f, 1.0f);
BLI_snprintf(str, sizeof(str), " %d", sc->user.framenr);
BLF_size(fontid, 11.0f, U.dpi);
slen= BLF_width(fontid, str);
fontsize= BLF_height(fontid, str);
/* get starting coordinates for drawing */
x= (float)sc->user.framenr * xscale;
y= 18;
/* draw green box around/behind text */
UI_ThemeColorShade(TH_CFRAME, 0);
glRectf(x, y, x+slen, y+fontsize+4);
/* draw current frame number - black text */
UI_ThemeColor(TH_TEXT);
BLF_position(fontid, x-5, y+2, 0.0f);
BLF_draw(fontid, str, strlen(str));
clip_draw_curfra_label(sc, (float)sc->user.framenr * xscale, 18);
/* restore view transform */
glScalef(xscale, 1.0, 1.0);
@@ -193,7 +173,7 @@ static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
}
}
static void draw_clip_tracks_curves(View2D *v2d, SpaceClip *sc)
static void draw_tracks_curves(View2D *v2d, SpaceClip *sc)
{
MovieClip *clip= ED_space_clip(sc);
MovieTracking *tracking= &clip->tracking;
@@ -222,7 +202,7 @@ static void draw_clip_tracks_curves(View2D *v2d, SpaceClip *sc)
clip_graph_tracking_values_iterate(sc, &userdata, tracking_segment_knot_cb, NULL, NULL);
}
static void draw_clip_frame_curves(SpaceClip *sc)
static void draw_frame_curves(SpaceClip *sc)
{
MovieClip *clip= ED_space_clip(sc);
MovieTracking *tracking= &clip->tracking;
@@ -253,7 +233,7 @@ static void draw_clip_frame_curves(SpaceClip *sc)
glEnd();
}
void draw_clip_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
{
View2D *v2d= &ar->v2d;
View2DGrid *grid;
@@ -265,10 +245,10 @@ void draw_clip_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
UI_view2d_grid_free(grid);
if(sc->flag&SC_SHOW_GRAPH_TRACKS)
draw_clip_tracks_curves(v2d, sc);
draw_tracks_curves(v2d, sc);
if(sc->flag&SC_SHOW_GRAPH_FRAMES)
draw_clip_frame_curves(sc);
draw_frame_curves(sc);
/* current frame */
draw_graph_cfra(sc, ar, scene);

View File

@@ -47,11 +47,12 @@ struct wmOperatorType;
void ED_clip_buttons_register(struct ARegionType *art);
/* clip_draw.c */
void draw_clip_main(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene);
void draw_clip_grease_pencil(struct bContext *C, int onlyv2d);
void clip_draw_main(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene);
void clip_draw_grease_pencil(struct bContext *C, int onlyv2d);
void clip_draw_curfra_label(struct SpaceClip *sc, float x, float y);
/* clip_graph_draw.c */
void draw_clip_graph(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene);
void clip_draw_graph(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene);
/* clip_graph_ops.c */
void CLIP_OT_graph_select(struct wmOperatorType *ot);
@@ -61,7 +62,6 @@ void CLIP_OT_graph_delete_knot(struct wmOperatorType *ot);
/* clip_ops.c */
void CLIP_OT_open(struct wmOperatorType *ot);
void CLIP_OT_reload(struct wmOperatorType *ot);
// void CLIP_OT_unlink(struct wmOperatorType *ot);
void CLIP_OT_view_pan(struct wmOperatorType *ot);
void CLIP_OT_view_zoom(wmOperatorType *ot);
void CLIP_OT_view_zoom_in(struct wmOperatorType *ot);
@@ -98,9 +98,6 @@ void clip_delete_marker(struct bContext *C, struct MovieClip *clip, struct Movie
void clip_view_center_to_point(struct SpaceClip *sc, float x, float y);
/* tracking_ops.c */
void clip_delete_track(struct bContext *C, struct MovieClip *clip, struct MovieTrackingTrack *track);
void clip_delete_marker(struct bContext *C, struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker);
void CLIP_OT_select(struct wmOperatorType *ot);
void CLIP_OT_select_all(struct wmOperatorType *ot);
void CLIP_OT_select_border(struct wmOperatorType *ot);

View File

@@ -700,16 +700,16 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar)
/* data... */
movieclip_main_area_set_view2d(sc, ar);
draw_clip_main(sc, ar, scene);
clip_draw_main(sc, ar, scene);
/* Grease Pencil */
draw_clip_grease_pencil((bContext *)C, 1);
clip_draw_grease_pencil((bContext *)C, 1);
/* reset view matrix */
UI_view2d_view_restore(C);
/* draw Grease Pencil - screen space only */
draw_clip_grease_pencil((bContext *)C, 0);
clip_draw_grease_pencil((bContext *)C, 0);
}
static void clip_main_area_listener(ARegion *ar, wmNotifier *wmn)
@@ -754,7 +754,7 @@ static void clip_preview_area_draw(const bContext *C, ARegion *ar)
UI_view2d_view_ortho(v2d);
/* data... */
draw_clip_graph(sc, ar, scene);
clip_draw_graph(sc, ar, scene);
/* reset view matrix */
UI_view2d_view_restore(C);

View File

@@ -2245,15 +2245,18 @@ static int detect_features_exec(bContext *C, wmOperator *op)
ImBuf *ibuf= BKE_movieclip_get_ibuf_flag(clip, &sc->user, 0);
MovieTrackingTrack *track= clip->tracking.tracks.first;
int detector= RNA_enum_get(op->ptr, "detector");
int use_grease_pencil= RNA_boolean_get(op->ptr, "use_grease_pencil");
int placement= RNA_enum_get(op->ptr, "placement");
int margin= RNA_int_get(op->ptr, "margin");
int min_trackness= RNA_int_get(op->ptr, "min_trackness");
int count= RNA_int_get(op->ptr, "count");
int min_distance= RNA_int_get(op->ptr, "min_distance");
int place_outside_layer= 0;
bGPDlayer *layer= NULL;
if(use_grease_pencil)
if(placement!=0) {
layer= detect_get_layer(clip);
place_outside_layer= placement==2;
}
/* deselect existing tracks */
while(track) {
@@ -2265,9 +2268,9 @@ static int detect_features_exec(bContext *C, wmOperator *op)
}
if(detector==0)
BKE_tracking_detect_fast(&clip->tracking, ibuf, sc->user.framenr, margin, min_trackness, min_distance, layer);
BKE_tracking_detect_fast(&clip->tracking, ibuf, sc->user.framenr, margin, min_trackness, min_distance, layer, place_outside_layer);
else
BKE_tracking_detect_moravec(&clip->tracking, ibuf, sc->user.framenr, margin, count, min_distance, layer);
BKE_tracking_detect_moravec(&clip->tracking, ibuf, sc->user.framenr, margin, count, min_distance, layer, place_outside_layer);
IMB_freeImBuf(ibuf);
@@ -2310,6 +2313,13 @@ void CLIP_OT_detect_features(wmOperatorType *ot)
{0, NULL, 0, NULL, NULL}
};
static EnumPropertyItem placement_items[] = {
{0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
{1, "INSIDE_GPENCIL", 0, "Inside grease pencil", "Place markers only inside areas oulined with grease pencil"},
{2, "OUTSIDE_GPENCIL", 0, "Outside grease pencil", "Place markers only outside areas oulined with grease pencil"},
{0, NULL, 0, NULL, NULL}
};
/* identifiers */
ot->name= "Detect Features";
ot->description= "Automatically detect features to track";
@@ -2325,7 +2335,7 @@ void CLIP_OT_detect_features(wmOperatorType *ot)
/* properties */
RNA_def_enum(ot->srna, "detector", detector_items, 0, "Detector", "Detector using for detecting features");
RNA_def_boolean(ot->srna, "use_grease_pencil", 0, "Use Grease Pencil", "Use grease pencil strokes from active layer to define zones where detection should happen");
RNA_def_enum(ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
RNA_def_int(ot->srna, "margin", 16, 0, INT_MAX, "Margin", "Only corners further than margin pixels from the image edges are considered", 0, 300);
RNA_def_int(ot->srna, "min_trackness", 16, 0, INT_MAX, "Trackness", "Minimum score to add a corner", 0, 300);
RNA_def_int(ot->srna, "count", 50, 1, INT_MAX, "Count", "Count of corners to detect", 0, 300);

View File

@@ -259,8 +259,8 @@ static SpaceLink *view3d_new(const bContext *C)
v3d->twtype= V3D_MANIP_TRANSLATE;
v3d->around= V3D_CENTROID;
v3d->bundle_size= 0.1f;
v3d->bundle_drawtype= OB_EMPTY_SPHERE;
v3d->bundle_size= 0.2f;
v3d->bundle_drawtype= OB_PLAINAXES;
/* header */
ar= MEM_callocN(sizeof(ARegion), "header for view3d");