Blender  V3.3
tracking_ops_detect.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 Blender Foundation. All rights reserved. */
3 
8 #include "DNA_gpencil_types.h"
9 #include "DNA_screen_types.h"
10 #include "DNA_space_types.h"
11 
12 #include "BKE_context.h"
13 #include "BKE_movieclip.h"
14 #include "BKE_report.h"
15 #include "BKE_tracking.h"
16 
17 #include "WM_api.h"
18 #include "WM_types.h"
19 
20 #include "ED_clip.h"
21 
22 #include "IMB_imbuf.h"
23 #include "IMB_imbuf_types.h"
24 
25 #include "RNA_access.h"
26 #include "RNA_define.h"
27 
28 #include "clip_intern.h"
29 #include "tracking_ops_intern.h"
30 
31 /********************** detect features operator *********************/
32 
34 {
35  if (clip->gpd == NULL) {
36  return NULL;
37  }
38  for (bGPDlayer *layer = clip->gpd->layers.first; layer != NULL; layer = layer->next) {
39  if (layer->flag & GP_LAYER_ACTIVE) {
40  return layer;
41  }
42  }
43  return NULL;
44 }
45 
47 {
50  int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
51  ImBuf *ibuf = BKE_movieclip_get_ibuf_flag(clip, &sc->user, clip_flag, MOVIECLIP_CACHE_SKIP);
52  MovieTracking *tracking = &clip->tracking;
53  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
54  int placement = RNA_enum_get(op->ptr, "placement");
55  int margin = RNA_int_get(op->ptr, "margin");
56  int min_distance = RNA_int_get(op->ptr, "min_distance");
57  float threshold = RNA_float_get(op->ptr, "threshold");
58  int place_outside_layer = 0;
59  int framenr = ED_space_clip_get_clip_frame_number(sc);
60  bGPDlayer *layer = NULL;
61 
62  if (!ibuf) {
63  BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
64  return OPERATOR_CANCELLED;
65  }
66 
67  if (placement != 0) {
68  layer = detect_get_layer(clip);
69  place_outside_layer = placement == 2;
70  }
71 
72  /* Deselect existing tracks. */
74  /* Run detector. */
76  tracksbase,
77  ibuf,
78  framenr,
79  margin,
80  threshold / 100000.0f,
81  min_distance,
82  layer,
83  place_outside_layer);
84 
85  IMB_freeImBuf(ibuf);
86 
89 
90  return OPERATOR_FINISHED;
91 }
92 
94 {
95  static const EnumPropertyItem placement_items[] = {
96  {0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
97  {1,
98  "INSIDE_GPENCIL",
99  0,
100  "Inside Annotated Area",
101  "Place markers only inside areas outlined with the Annotation tool"},
102  {2,
103  "OUTSIDE_GPENCIL",
104  0,
105  "Outside Annotated Area",
106  "Place markers only outside areas outlined with the Annotation tool"},
107  {0, NULL, 0, NULL, NULL},
108  };
109 
110  /* identifiers */
111  ot->name = "Detect Features";
112  ot->description = "Automatically detect features and place markers to track";
113  ot->idname = "CLIP_OT_detect_features";
114 
115  /* api callbacks */
118 
119  /* flags */
121 
122  /* properties */
123  RNA_def_enum(
124  ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
126  "margin",
127  16,
128  0,
129  INT_MAX,
130  "Margin",
131  "Only features further than margin pixels from the image "
132  "edges are considered",
133  0,
134  300);
136  "threshold",
137  0.5f,
138  0.0001f,
139  FLT_MAX,
140  "Threshold",
141  "Threshold level to consider feature good enough for tracking",
142  0.0001f,
143  FLT_MAX);
145  "min_distance",
146  120,
147  0,
148  INT_MAX,
149  "Distance",
150  "Minimal distance accepted between two features",
151  0,
152  300);
153 }
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:923
#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:1334
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
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:346
void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking)
Definition: tracking.c:3411
@ 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:231
bool ED_space_clip_tracking_poll(struct bContext *C)
Definition: clip_editor.c:83
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:570
Contains defines and structs used throughout the imbuf module.
#define C
Definition: RandGen.cpp:25
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_MOVIECLIP
Definition: WM_types.h:347
#define NA_EDITED
Definition: WM_types.h:523
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
ccl_gpu_kernel_postfix ccl_global float int int int int float threshold
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
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:3836
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:3597
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:3783
void * first
Definition: DNA_listBase.h:31
struct MovieTracking tracking
struct bGPdata * gpd
struct MovieClipUser user
ListBase layers
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
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:3479