Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-10-08 17:53:59 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2014-01-28 13:37:19 +0400
commit9178dc9d384f18ab2f23656fb6b01a3b444526ef (patch)
tree7ca0ded6874ce96c9ac7747dca790b0a12ae5e90 /source
parentf194ab765996cb9830da2396f28f1ddad1778d0b (diff)
Rework detector API and implement Harris detector
Switch the detector API to a single function which accepts a float image and detector options. This makes usage of feature detection more unified across different algorithms. Options structure is pretty much straightforward and contains detector to be used and all the detector-specific settings. Also implemented Harris feature detection algorithm which is not as fast as FAST one but is expected to detect more robust feature points. It is also likely that less features are detected, but better quality than quantity. Blender will now use Harris detector by default, later we'll remove FAST detector.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_tracking.h4
-rw-r--r--source/blender/blenkernel/intern/tracking_detect.c77
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c12
3 files changed, 51 insertions, 42 deletions
diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h
index 9936416847b..62149bbaf88 100644
--- a/source/blender/blenkernel/BKE_tracking.h
+++ b/source/blender/blenkernel/BKE_tracking.h
@@ -242,6 +242,10 @@ void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ListBase *t
int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer,
bool place_outside_layer);
+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);
+
/* **** 2D stabilization **** */
void BKE_tracking_stabilization_data_get(struct MovieTracking *tracking, int framenr, int width, int height,
float translation[2], float *scale, float *angle);
diff --git a/source/blender/blenkernel/intern/tracking_detect.c b/source/blender/blenkernel/intern/tracking_detect.c
index b262844d40f..65fd997ae6c 100644
--- a/source/blender/blenkernel/intern/tracking_detect.c
+++ b/source/blender/blenkernel/intern/tracking_detect.c
@@ -113,8 +113,11 @@ static void detect_retrieve_libmv_features(MovieTracking *tracking, ListBase *tr
libmv_getFeature(features, a, &x, &y, &score, &size);
- xu = x / width;
- yu = y / height;
+ /* In Libmv integer coordinate points to pixel center, in blender
+ * it's not. Need to add 0.5px offset to center.
+ */
+ xu = (x + 0.5f) / width;
+ yu = (y + 0.5f) / height;
if (layer)
ok = check_point_in_layer(layer, xu, yu) != place_outside_layer;
@@ -128,36 +131,26 @@ static void detect_retrieve_libmv_features(MovieTracking *tracking, ListBase *tr
}
}
-/* Get a gray-scale unsigned char buffer from given image buffer
- * wich will be used for feature detection.
- */
-static unsigned char *detect_get_frame_ucharbuf(ImBuf *ibuf)
+static void run_configured_detector(MovieTracking *tracking, ListBase *tracksbase,
+ ImBuf *ibuf, int framenr, bGPDlayer *layer, bool place_outside_layer,
+ libmv_DetectOptions *options)
{
- int x, y;
- unsigned char *pixels, *cp;
-
- cp = pixels = MEM_callocN(ibuf->x * ibuf->y * sizeof(unsigned char), "tracking ucharBuf");
- for (y = 0; y < ibuf->y; y++) {
- for (x = 0; x < ibuf->x; x++) {
- int pixel = ibuf->x * y + x;
-
- if (ibuf->rect_float) {
- const float *rrgbf = ibuf->rect_float + pixel * 4;
- const float gray_f = 0.2126f * rrgbf[0] + 0.7152f * rrgbf[1] + 0.0722f * rrgbf[2];
+ struct libmv_Features *features = NULL;
- *cp = FTOCHAR(gray_f);
- }
- else {
- const unsigned char *rrgb = (unsigned char *)ibuf->rect + pixel * 4;
+ if (ibuf->rect_float) {
+ features = libmv_detectFeaturesFloat(ibuf->rect_float, ibuf->x, ibuf->y, 4, options);
+ }
+ else if (ibuf->rect) {
+ features = libmv_detectFeaturesByte((unsigned char *) ibuf->rect, ibuf->x, ibuf->y, 4, options);
+ }
- *cp = 0.2126f * rrgb[0] + 0.7152f * rrgb[1] + 0.0722f * rrgb[2];
- }
+ if (features != NULL) {
+ detect_retrieve_libmv_features(tracking, tracksbase, features,
+ framenr, ibuf->x, ibuf->y, layer,
+ place_outside_layer);
- cp++;
- }
+ libmv_featuresDestroy(features);
}
-
- return pixels;
}
/* Detect features using FAST detector */
@@ -165,17 +158,29 @@ void BKE_tracking_detect_fast(MovieTracking *tracking, ListBase *tracksbase, ImB
int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer,
bool place_outside_layer)
{
- struct libmv_Features *features;
- unsigned char *pixels = detect_get_frame_ucharbuf(ibuf);
+ libmv_DetectOptions options = {0};
- features = libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x,
- margin, min_trackness, min_distance);
+ options.detector = LIBMV_DETECTOR_FAST;
+ options.margin = margin;
+ options.min_distance = min_distance;
+ options.fast_min_trackness = min_trackness;
- MEM_freeN(pixels);
+ run_configured_detector(tracking, tracksbase, ibuf, framenr, layer,
+ place_outside_layer, &options);
+}
+
+/* Detect features using Harris detector */
+void BKE_tracking_detect_harris(MovieTracking *tracking, ListBase *tracksbase, ImBuf *ibuf,
+ int framenr, int margin, float threshold, int min_distance, bGPDlayer *layer,
+ bool place_outside_layer)
+{
+ libmv_DetectOptions options = {0};
- detect_retrieve_libmv_features(tracking, tracksbase, features,
- framenr, ibuf->x, ibuf->y, layer,
- place_outside_layer);
+ options.detector = LIBMV_DETECTOR_HARRIS;
+ options.margin = margin;
+ options.min_distance = min_distance;
+ options.harris_threshold = threshold;
- libmv_featuresDestroy(features);
+ run_configured_detector(tracking, tracksbase, ibuf, framenr, layer,
+ place_outside_layer, &options);
}
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index 1269f9536b6..59cfe88e8c9 100644
--- a/source/blender/editors/space_clip/tracking_ops.c
+++ b/source/blender/editors/space_clip/tracking_ops.c
@@ -2913,8 +2913,8 @@ static int detect_features_exec(bContext *C, wmOperator *op)
MovieTrackingTrack *track = tracksbase->first;
int placement = RNA_enum_get(op->ptr, "placement");
int margin = RNA_int_get(op->ptr, "margin");
- int min_trackability = RNA_int_get(op->ptr, "min_trackability");
int min_distance = RNA_int_get(op->ptr, "min_distance");
+ float threshold = RNA_float_get(op->ptr, "threshold");
int place_outside_layer = 0;
int framenr = ED_space_clip_get_clip_frame_number(sc);
bGPDlayer *layer = NULL;
@@ -2938,8 +2938,8 @@ static int detect_features_exec(bContext *C, wmOperator *op)
track = track->next;
}
- BKE_tracking_detect_fast(tracking, tracksbase, ibuf, framenr, margin,
- min_trackability, min_distance, layer, place_outside_layer);
+ BKE_tracking_detect_harris(tracking, tracksbase, ibuf, framenr, margin,
+ threshold / 100000.0f, min_distance, layer, place_outside_layer);
IMB_freeImBuf(ibuf);
@@ -2972,9 +2972,9 @@ void CLIP_OT_detect_features(wmOperatorType *ot)
/* properties */
RNA_def_enum(ot->srna, "placement", placement_items, 0, "Placement", "Placement for detected features");
- RNA_def_int(ot->srna, "margin", 16, 0, INT_MAX, "Margin", "Only corners further than margin pixels from the image edges are considered", 0, 300);
- RNA_def_int(ot->srna, "min_trackability", 16, 0, INT_MAX, "Trackability", "Minimum trackability score to add a corner", 0, 300);
- RNA_def_int(ot->srna, "min_distance", 120, 0, INT_MAX, "Distance", "Minimal distance accepted between two corners", 0, 300);
+ RNA_def_int(ot->srna, "margin", 16, 0, INT_MAX, "Margin", "Only features further than margin pixels from the image edges are considered", 0, 300);
+ RNA_def_float(ot->srna, "threshold", 1.0f, 0.0001f, FLT_MAX, "Threshold", "Threshold level to consider feature good enough for tracking", 0.0001f, FLT_MAX);
+ RNA_def_int(ot->srna, "min_distance", 120, 0, INT_MAX, "Distance", "Minimal distance accepted between two features", 0, 300);
}
/********************** frame jump operator *********************/