Blender V5.0
tracking_ops_detect.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "DNA_screen_types.h"
11#include "DNA_space_types.h"
12
13#include "BLI_listbase.h"
14
15#include "BKE_context.hh"
16#include "BKE_movieclip.h"
17#include "BKE_report.hh"
18#include "BKE_tracking.h"
19
20#include "WM_api.hh"
21#include "WM_types.hh"
22
23#include "ED_clip.hh"
24
25#include "IMB_imbuf.hh"
26#include "IMB_imbuf_types.hh"
27
28#include "RNA_access.hh"
29#include "RNA_define.hh"
30
31#include "clip_intern.hh"
33
34/********************** detect features operator *********************/
35
37{
38 if (clip->gpd == nullptr) {
39 return nullptr;
40 }
41
42 LISTBASE_FOREACH (bGPDlayer *, layer, &clip->gpd->layers) {
43 if (layer->flag & GP_LAYER_ACTIVE) {
44 return layer;
45 }
46 }
47 return nullptr;
48}
49
51{
54 int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
55 ImBuf *ibuf = BKE_movieclip_get_ibuf_flag(clip, &sc->user, clip_flag, MOVIECLIP_CACHE_SKIP);
56 MovieTracking *tracking = &clip->tracking;
57 MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
58 const int placement = RNA_enum_get(op->ptr, "placement");
59 const int margin = RNA_int_get(op->ptr, "margin");
60 const int min_distance = RNA_int_get(op->ptr, "min_distance");
61 const float threshold = RNA_float_get(op->ptr, "threshold");
62 const int framenr = ED_space_clip_get_clip_frame_number(sc);
63 bGPDlayer *layer = nullptr;
64 int place_outside_layer = 0;
65
66 if (!ibuf) {
67 BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
68 return OPERATOR_CANCELLED;
69 }
70
71 if (placement != 0) {
72 layer = detect_get_layer(clip);
73 place_outside_layer = placement == 2;
74 }
75
76 /* Deselect existing tracks. */
77 ed_tracking_deselect_all_tracks(&tracking_object->tracks);
78
79 /* Run detector. */
81 &tracking_object->tracks,
82 ibuf,
83 framenr,
84 margin,
85 threshold / 100000.0f,
86 min_distance,
87 layer,
88 place_outside_layer);
89
90 IMB_freeImBuf(ibuf);
91
94
95 return OPERATOR_FINISHED;
96}
97
99{
100 static const EnumPropertyItem placement_items[] = {
101 {0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
102 {1,
103 "INSIDE_GPENCIL",
104 0,
105 "Inside Annotated Area",
106 "Place markers only inside areas outlined with the Annotation tool"},
107 {2,
108 "OUTSIDE_GPENCIL",
109 0,
110 "Outside Annotated Area",
111 "Place markers only outside areas outlined with the Annotation tool"},
112 {0, nullptr, 0, nullptr, nullptr},
113 };
114
115 /* identifiers */
116 ot->name = "Detect Features";
117 ot->description = "Automatically detect features and place markers to track";
118 ot->idname = "CLIP_OT_detect_features";
119
120 /* API callbacks. */
121 ot->exec = detect_features_exec;
123
124 /* flags */
126
127 /* properties */
129 ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
130 RNA_def_int(ot->srna,
131 "margin",
132 16,
133 0,
134 INT_MAX,
135 "Margin",
136 "Only features further than margin pixels from the image "
137 "edges are considered",
138 0,
139 300);
140 RNA_def_float(ot->srna,
141 "threshold",
142 0.5f,
143 0.0001f,
144 FLT_MAX,
145 "Threshold",
146 "Threshold level to consider feature good enough for tracking",
147 0.0001f,
148 FLT_MAX);
149 RNA_def_int(ot->srna,
150 "min_distance",
151 120,
152 0,
153 INT_MAX,
154 "Distance",
155 "Minimal distance accepted between two features",
156 0,
157 300);
158}
SpaceClip * CTX_wm_space_clip(const bContext *C)
#define MOVIECLIP_CACHE_SKIP
struct ImBuf * BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, const struct MovieClipUser *user, int flag, int cache_flag)
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
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 MovieTrackingObject * BKE_tracking_object_get_active(const struct MovieTracking *tracking)
void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking)
Definition tracking.cc:3439
#define LISTBASE_FOREACH(type, var, list)
@ MCLIP_TIMECODE_FLAGS
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
int ED_space_clip_get_clip_frame_number(const SpaceClip *sc)
bool ED_space_clip_tracking_poll(bContext *C)
void IMB_freeImBuf(ImBuf *ibuf)
#define C
Definition RandGen.cpp:29
#define NC_MOVIECLIP
Definition WM_types.hh:397
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define NA_EDITED
Definition WM_types.hh:584
int RNA_int_get(PointerRNA *ptr, const char *name)
float RNA_float_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
#define FLT_MAX
Definition stdcycles.h:14
struct MovieTracking tracking
struct bGPdata * gpd
struct MovieClipUser user
struct ReportList * reports
struct PointerRNA * ptr
static bGPDlayer * detect_get_layer(MovieClip *clip)
void CLIP_OT_detect_features(wmOperatorType *ot)
static wmOperatorStatus detect_features_exec(bContext *C, wmOperator *op)
void ed_tracking_deselect_all_tracks(ListBase *tracks_base)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4237