Blender  V2.93
tracking_ops_detect.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_gpencil_types.h"
25 #include "DNA_screen_types.h"
26 #include "DNA_space_types.h"
27 
28 #include "BKE_context.h"
29 #include "BKE_movieclip.h"
30 #include "BKE_report.h"
31 #include "BKE_tracking.h"
32 
33 #include "WM_api.h"
34 #include "WM_types.h"
35 
36 #include "ED_clip.h"
37 
38 #include "IMB_imbuf.h"
39 #include "IMB_imbuf_types.h"
40 
41 #include "RNA_access.h"
42 #include "RNA_define.h"
43 
44 #include "clip_intern.h"
45 #include "tracking_ops_intern.h"
46 
47 /********************** detect features operator *********************/
48 
50 {
51  if (clip->gpd == NULL) {
52  return NULL;
53  }
54  for (bGPDlayer *layer = clip->gpd->layers.first; layer != NULL; layer = layer->next) {
55  if (layer->flag & GP_LAYER_ACTIVE) {
56  return layer;
57  }
58  }
59  return NULL;
60 }
61 
63 {
66  int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
67  ImBuf *ibuf = BKE_movieclip_get_ibuf_flag(clip, &sc->user, clip_flag, MOVIECLIP_CACHE_SKIP);
68  MovieTracking *tracking = &clip->tracking;
69  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
70  int placement = RNA_enum_get(op->ptr, "placement");
71  int margin = RNA_int_get(op->ptr, "margin");
72  int min_distance = RNA_int_get(op->ptr, "min_distance");
73  float threshold = RNA_float_get(op->ptr, "threshold");
74  int place_outside_layer = 0;
75  int framenr = ED_space_clip_get_clip_frame_number(sc);
76  bGPDlayer *layer = NULL;
77 
78  if (!ibuf) {
79  BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
80  return OPERATOR_CANCELLED;
81  }
82 
83  if (placement != 0) {
84  layer = detect_get_layer(clip);
85  place_outside_layer = placement == 2;
86  }
87 
88  /* Deselect existing tracks. */
90  /* Run detector. */
92  tracksbase,
93  ibuf,
94  framenr,
95  margin,
96  threshold / 100000.0f,
97  min_distance,
98  layer,
99  place_outside_layer);
100 
101  IMB_freeImBuf(ibuf);
102 
105 
106  return OPERATOR_FINISHED;
107 }
108 
110 {
111  static const EnumPropertyItem placement_items[] = {
112  {0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
113  {1,
114  "INSIDE_GPENCIL",
115  0,
116  "Inside Annotated Area",
117  "Place markers only inside areas outlined with the Annotation tool"},
118  {2,
119  "OUTSIDE_GPENCIL",
120  0,
121  "Outside Annotated Area",
122  "Place markers only outside areas outlined with the Annotation tool"},
123  {0, NULL, 0, NULL, NULL},
124  };
125 
126  /* identifiers */
127  ot->name = "Detect Features";
128  ot->description = "Automatically detect features and place markers to track";
129  ot->idname = "CLIP_OT_detect_features";
130 
131  /* api callbacks */
134 
135  /* flags */
137 
138  /* properties */
139  RNA_def_enum(
140  ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
142  "margin",
143  16,
144  0,
145  INT_MAX,
146  "Margin",
147  "Only features further than margin pixels from the image "
148  "edges are considered",
149  0,
150  300);
152  "threshold",
153  0.5f,
154  0.0001f,
155  FLT_MAX,
156  "Threshold",
157  "Threshold level to consider feature good enough for tracking",
158  0.0001f,
159  FLT_MAX);
161  "min_distance",
162  120,
163  0,
164  INT_MAX,
165  "Distance",
166  "Minimal distance accepted between two features",
167  0,
168  300);
169 }
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
#define MOVIECLIP_CACHE_SKIP
struct ImBuf * BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, struct MovieClipUser *user, int flag, int cache_flag)
Definition: movieclip.c:1354
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_tracking_detect_harris(struct MovieTracking *tracking, struct ListBase *tracksbase, struct ImBuf *ibuf, int framenr, int margin, float threshold, int min_distance, struct bGPDlayer *layer, bool place_outside_layer)
struct ListBase * BKE_tracking_get_active_tracks(struct MovieTracking *tracking)
Definition: tracking.c:365
void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking)
Definition: tracking.c:3321
@ GP_LAYER_ACTIVE
@ MCLIP_TIMECODE_FLAGS
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc)
Definition: clip_editor.c:227
bool ED_space_clip_tracking_poll(struct bContext *C)
Definition: clip_editor.c:98
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:572
void IMB_freeImBuf(struct ImBuf *ibuf)
Definition: allocimbuf.c:211
Contains defines and structs used throughout the imbuf module.
#define C
Definition: RandGen.cpp:39
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NC_MOVIECLIP
Definition: WM_types.h:298
#define NA_EDITED
Definition: WM_types.h:462
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3825
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
void * first
Definition: DNA_listBase.h:47
struct MovieTracking tracking
struct bGPdata * gpd
struct MovieClipUser user
ListBase layers
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct PointerRNA * ptr
void CLIP_OT_detect_features(wmOperatorType *ot)
static bGPDlayer * detect_get_layer(MovieClip *clip)
static int detect_features_exec(bContext *C, wmOperator *op)
void ed_tracking_deselect_all_tracks(struct ListBase *tracks_base)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156