Blender V5.3
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_space_types.h"
11
12#include "BLI_listbase.hh"
13
14#include "BKE_context.hh"
15#include "BKE_movieclip.hh"
16#include "BKE_report.hh"
17#include "BKE_tracking.hh"
18
19#include "WM_api.hh"
20#include "WM_types.hh"
21
22#include "ED_clip.hh"
23
24#include "IMB_imbuf.hh"
25#include "IMB_imbuf_types.hh"
26
27#include "RNA_access.hh"
28#include "RNA_define.hh"
29
30#include "clip_intern.hh"
32
33namespace blender {
34
35/********************** detect features operator *********************/
36
38{
39 if (clip->gpd == nullptr) {
40 return nullptr;
41 }
42
43 for (bGPDlayer &layer : clip->gpd->layers) {
44 if (layer.flag & GP_LAYER_ACTIVE) {
45 return &layer;
46 }
47 }
48 return nullptr;
49}
50
52{
57 clip, &sc->user, clip_flag, MovieClipCacheFlag::SkipCache);
58 MovieTracking *tracking = &clip->tracking;
59 MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
60 const int placement = RNA_enum_get(op->ptr, "placement");
61 const int margin = RNA_int_get(op->ptr, "margin");
62 const int min_distance = RNA_int_get(op->ptr, "min_distance");
63 const float threshold = RNA_float_get(op->ptr, "threshold");
64 const int framenr = ED_space_clip_get_clip_frame_number(sc);
65 bGPDlayer *layer = nullptr;
66 int place_outside_layer = 0;
67
68 if (!ibuf) {
69 BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
70 return OPERATOR_CANCELLED;
71 }
72
73 if (placement != 0) {
74 layer = detect_get_layer(clip);
75 place_outside_layer = placement == 2;
76 }
77
78 /* Deselect existing tracks. */
79 ed_tracking_deselect_all_tracks(&tracking_object->tracks);
80
81 /* Run detector. */
83 &tracking_object->tracks,
84 ibuf,
85 framenr,
86 margin,
87 threshold / 100000.0f,
88 min_distance,
89 layer,
90 place_outside_layer);
91
92 IMB_freeImBuf(ibuf);
93
96
97 return OPERATOR_FINISHED;
98}
99
101{
102 static const EnumPropertyItem placement_items[] = {
103 {0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
104 {1,
105 "INSIDE_GPENCIL",
106 0,
107 "Inside Annotated Area",
108 "Place markers only inside areas outlined with the Annotation tool"},
109 {2,
110 "OUTSIDE_GPENCIL",
111 0,
112 "Outside Annotated Area",
113 "Place markers only outside areas outlined with the Annotation tool"},
114 {0, nullptr, 0, nullptr, nullptr},
115 };
116
117 /* identifiers */
118 ot->name = "Detect Features";
119 ot->description = "Automatically detect features and place markers to track";
120 ot->idname = "CLIP_OT_detect_features";
121
122 /* API callbacks. */
125
126 /* flags */
128
129 /* properties */
131 ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
132 RNA_def_int(ot->srna,
133 "margin",
134 16,
135 0,
136 INT_MAX,
137 "Margin",
138 "Only features further than margin pixels from the image "
139 "edges are considered",
140 0,
141 300);
143 "threshold",
144 0.5f,
145 0.0001f,
146 FLT_MAX,
147 "Threshold",
148 "Threshold level to consider feature good enough for tracking",
149 0.0001f,
150 FLT_MAX);
151 RNA_def_int(ot->srna,
152 "min_distance",
153 120,
154 0,
155 INT_MAX,
156 "Distance",
157 "Minimal distance accepted between two features",
158 0,
159 300);
160}
161
162} // namespace blender
#define C
Definition RandGen.cpp:29
#define NC_MOVIECLIP
Definition WM_types.hh:410
#define NA_EDITED
Definition WM_types.hh:634
#define FLT_MAX
#define INT_MAX
#define layer
BMesh Iterators.
int RNA_enum_get(PointerRNA *ptr, const char *name)
MovieTrackingObject * BKE_tracking_object_get_active(const MovieTracking *tracking)
Definition tracking.cc:1982
SpaceClip * CTX_wm_space_clip(const bContext *C)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
void ed_tracking_deselect_all_tracks(ListBaseT< MovieTrackingTrack > *tracks_base)
void BKE_tracking_dopesheet_tag_update(MovieTracking *tracking)
Definition tracking.cc:3355
void CLIP_OT_detect_features(wmOperatorType *ot)
void IMB_freeImBuf(ImBuf *ibuf)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static bGPDlayer * detect_get_layer(MovieClip *clip)
int ED_space_clip_get_clip_frame_number(const SpaceClip *sc)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
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)
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
ImBuf * BKE_movieclip_get_ibuf_flag(MovieClip *clip, const MovieClipUser *user, MovieClipFlag flag, MovieClipCacheFlag cache_flag)
bool ED_space_clip_tracking_poll(bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
static wmOperatorStatus detect_features_exec(bContext *C, wmOperator *op)
void BKE_tracking_detect_harris(MovieTracking *tracking, ListBaseT< MovieTrackingTrack > *tracksbase, ImBuf *ibuf, int framenr, int margin, float threshold, int min_distance, bGPDlayer *layer, bool place_outside_layer)
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)
float RNA_float_get(PointerRNA *ptr, const char *name)
struct MovieTracking tracking
ListBaseT< MovieTrackingTrack > tracks
struct MovieClipUser user
ListBaseT< bGPDlayer > layers
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct ReportList * reports