Blender V4.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
10#include "DNA_screen_types.h"
11#include "DNA_space_types.h"
12
13#include "BKE_context.hh"
14#include "BKE_movieclip.h"
15#include "BKE_report.hh"
16#include "BKE_tracking.h"
17
18#include "WM_api.hh"
19#include "WM_types.hh"
20
21#include "ED_clip.hh"
22
23#include "IMB_imbuf.hh"
24#include "IMB_imbuf_types.hh"
25
26#include "RNA_access.hh"
27#include "RNA_define.hh"
28
29#include "clip_intern.hh"
31
32/********************** detect features operator *********************/
33
35{
36 if (clip->gpd == nullptr) {
37 return nullptr;
38 }
39
40 LISTBASE_FOREACH (bGPDlayer *, layer, &clip->gpd->layers) {
41 if (layer->flag & GP_LAYER_ACTIVE) {
42 return layer;
43 }
44 }
45 return nullptr;
46}
47
49{
52 int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
53 ImBuf *ibuf = BKE_movieclip_get_ibuf_flag(clip, &sc->user, clip_flag, MOVIECLIP_CACHE_SKIP);
54 MovieTracking *tracking = &clip->tracking;
55 MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
56 const int placement = RNA_enum_get(op->ptr, "placement");
57 const int margin = RNA_int_get(op->ptr, "margin");
58 const int min_distance = RNA_int_get(op->ptr, "min_distance");
59 const float threshold = RNA_float_get(op->ptr, "threshold");
60 const int framenr = ED_space_clip_get_clip_frame_number(sc);
61 bGPDlayer *layer = nullptr;
62 int place_outside_layer = 0;
63
64 if (!ibuf) {
65 BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
66 return OPERATOR_CANCELLED;
67 }
68
69 if (placement != 0) {
70 layer = detect_get_layer(clip);
71 place_outside_layer = placement == 2;
72 }
73
74 /* Deselect existing tracks. */
75 ed_tracking_deselect_all_tracks(&tracking_object->tracks);
76
77 /* Run detector. */
79 &tracking_object->tracks,
80 ibuf,
81 framenr,
82 margin,
83 threshold / 100000.0f,
84 min_distance,
85 layer,
86 place_outside_layer);
87
88 IMB_freeImBuf(ibuf);
89
92
93 return OPERATOR_FINISHED;
94}
95
97{
98 static const EnumPropertyItem placement_items[] = {
99 {0, "FRAME", 0, "Whole Frame", "Place markers across the whole frame"},
100 {1,
101 "INSIDE_GPENCIL",
102 0,
103 "Inside Annotated Area",
104 "Place markers only inside areas outlined with the Annotation tool"},
105 {2,
106 "OUTSIDE_GPENCIL",
107 0,
108 "Outside Annotated Area",
109 "Place markers only outside areas outlined with the Annotation tool"},
110 {0, nullptr, 0, nullptr, nullptr},
111 };
112
113 /* identifiers */
114 ot->name = "Detect Features";
115 ot->description = "Automatically detect features and place markers to track";
116 ot->idname = "CLIP_OT_detect_features";
117
118 /* api callbacks */
121
122 /* flags */
124
125 /* properties */
127 ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
129 "margin",
130 16,
131 0,
132 INT_MAX,
133 "Margin",
134 "Only features further than margin pixels from the image "
135 "edges are considered",
136 0,
137 300);
139 "threshold",
140 0.5f,
141 0.0001f,
142 FLT_MAX,
143 "Threshold",
144 "Threshold level to consider feature good enough for tracking",
145 0.0001f,
146 FLT_MAX);
148 "min_distance",
149 120,
150 0,
151 INT_MAX,
152 "Distance",
153 "Minimal distance accepted between two features",
154 0,
155 300);
156}
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)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
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:3411
#define LISTBASE_FOREACH(type, var, list)
@ MCLIP_TIMECODE_FLAGS
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)
Contains defines and structs used throughout the imbuf module.
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define NC_MOVIECLIP
Definition WM_types.hh:364
#define NA_EDITED
Definition WM_types.hh:550
void IMB_freeImBuf(ImBuf *)
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 MovieClipUser user
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct PointerRNA * ptr
static bGPDlayer * detect_get_layer(MovieClip *clip)
void CLIP_OT_detect_features(wmOperatorType *ot)
static int 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:4125