[Bf-blender-cvs] [9178dc9] master: Rework detector API and implement Harris detector

Sergey Sharybin noreply at git.blender.org
Tue Jan 28 10:51:48 CET 2014


Commit: 9178dc9d384f18ab2f23656fb6b01a3b444526ef
Author: Sergey Sharybin
Date:   Tue Oct 8 19:53:59 2013 +0600
https://developer.blender.org/rB9178dc9d384f18ab2f23656fb6b01a3b444526ef

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.

===================================================================

M	extern/libmv/CMakeLists.txt
M	extern/libmv/ChangeLog
M	extern/libmv/files.txt
M	extern/libmv/libmv-capi.cc
M	extern/libmv/libmv-capi.h
M	extern/libmv/libmv-capi_stub.cc
M	extern/libmv/libmv/image/array_nd.h
M	extern/libmv/libmv/image/convolve.cc
A	extern/libmv/libmv/image/image_converter.h
M	extern/libmv/libmv/simple_pipeline/detect.cc
M	extern/libmv/libmv/simple_pipeline/detect.h
M	source/blender/blenkernel/BKE_tracking.h
M	source/blender/blenkernel/intern/tracking_detect.c
M	source/blender/editors/space_clip/tracking_ops.c

===================================================================

diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt
index 80a212b..ef7e49b 100644
--- a/extern/libmv/CMakeLists.txt
+++ b/extern/libmv/CMakeLists.txt
@@ -103,6 +103,7 @@ if(WITH_LIBMV)
 		libmv/image/array_nd.h
 		libmv/image/convolve.h
 		libmv/image/correlation.h
+		libmv/image/image_converter.h
 		libmv/image/image.h
 		libmv/image/sample.h
 		libmv/image/tuple.h
diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog
index c34ea06..225138b 100644
--- a/extern/libmv/ChangeLog
+++ b/extern/libmv/ChangeLog
@@ -1,3 +1,30 @@
+commit b63b8d6989f460fda7d963a2c8b21e8ffa6f8066
+Author: Sergey Sharybin <sergey.vfx at gmail.com>
+Date:   Fri Jan 24 19:32:34 2014 +0600
+
+    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.
+    
+    Reviewers: keir
+    
+    Differential Revision: https://developer.blender.org/D258
+
+commit 6458915f64fceba108c5279b7320ca8c76e8a742
+Author: Sergey Sharybin <sergey.vfx at gmail.com>
+Date:   Fri Jan 24 19:14:18 2014 +0600
+
+    Add arcanist configuration file
+
 commit 0a69fadadc5aacbd339f839ac5bd12c3571278b1
 Author: Sergey Sharybin <sergey.vfx at gmail.com>
 Date:   Thu Jan 9 15:50:11 2014 +0600
@@ -659,29 +686,3 @@ Date:   Sat Apr 6 00:38:40 2013 +0600
     
     Also fixed variable shadowing which lead to wrong
     markers positions (were either zero or undefined).
-
-commit a597ca9291ff7c6e209e0500945568afa84d8b4e
-Author: Sergey Sharybin <sergey.vfx at gmail.com>
-Date:   Sat Apr 6 00:12:12 2013 +0600
-
-    Camera intrinsics unit tests fixes
-    
-    - Existing test ApplyIsInvertibleSimple was not
-      doing right thing - distortion model used there
-      was ininvertible.
-    
-      Tweaked parameters in a way model is invertible now.
-    
-    - Added some own tests which tests;
-    
-      * Principal point always maps from pixel space to
-        zero normalized position.
-    
-      * Some basic tests to check whether individual
-        apply/invert works correct.
-
-commit a9a3016c7beb02e62655221d46783b206010d04c
-Author: Sergey Sharybin <sergey.vfx at gmail.com>
-Date:   Thu Apr 4 02:59:58 2013 +0600
-
-    Suppress strict compiler warnings in glags/glog libraries
diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt
index e5297c7..a639ea3 100644
--- a/extern/libmv/files.txt
+++ b/extern/libmv/files.txt
@@ -7,6 +7,7 @@ libmv/image/array_nd.h
 libmv/image/convolve.cc
 libmv/image/convolve.h
 libmv/image/correlation.h
+libmv/image/image_converter.h
 libmv/image/image.h
 libmv/image/sample.h
 libmv/image/tuple.h
diff --git a/extern/libmv/libmv-capi.cc b/extern/libmv/libmv-capi.cc
index 474501a..9a536f7 100644
--- a/extern/libmv/libmv-capi.cc
+++ b/extern/libmv/libmv-capi.cc
@@ -58,6 +58,14 @@
 #include "libmv/simple_pipeline/reconstruction_scale.h"
 #include "libmv/simple_pipeline/keyframe_selection.h"
 
+#include "libmv/multiview/homography.h"
+
+#include "libmv/image/convolve.h"
+
+#ifdef _MSC_VER
+#  define snprintf _snprintf
+#endif
+
 struct libmv_Reconstruction {
 	libmv::EuclideanReconstruction reconstruction;
 
@@ -69,7 +77,7 @@ struct libmv_Reconstruction {
 };
 
 struct libmv_Features {
-	int count, margin;
+	int count;
 	libmv::Feature *features;
 };
 
@@ -107,6 +115,21 @@ void libmv_setLoggingVerbosity(int verbosity)
 
 /* ************ Utility ************ */
 
+static void byteBufToImage(const unsigned char *buf, int width, int height, int channels, libmv::FloatImage *image)
+{
+	int x, y, k, a = 0;
+
+	image->Resize(height, width, channels);
+
+	for (y = 0; y < height; y++) {
+		for (x = 0; x < width; x++) {
+			for (k = 0; k < channels; k++) {
+				(*image)(y, x, k) = (float)buf[a++] / 255.0f;
+			}
+		}
+	}
+}
+
 static void floatBufToImage(const float *buf, int width, int height, int channels, libmv::FloatImage *image)
 {
 	int x, y, k, a = 0;
@@ -833,63 +856,88 @@ struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics(struct libm
 
 /* ************ Feature detector ************ */
 
-struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data,
-                                                int width, int height, int stride,
-                                                int margin, int min_trackness, int min_distance)
+static libmv_Features *libmv_featuresFromVector(
+	const libmv::vector<libmv::Feature> &features)
 {
-	libmv::Feature *features = NULL;
-	std::vector<libmv::Feature> v;
 	struct libmv_Features *libmv_features = LIBMV_STRUCT_NEW(libmv_Features, 1);
-	int i = 0, count;
-
-	if (margin) {
-		data += margin * stride+margin;
-		width -= 2 * margin;
-		height -= 2 * margin;
-	}
-
-	v = libmv::DetectFAST(data, width, height, stride, min_trackness, min_distance);
-
-	count = v.size();
-
+	int count = features.size();
 	if (count) {
-		features = LIBMV_STRUCT_NEW(libmv::Feature, count);
+		libmv_features->features = LIBMV_STRUCT_NEW(libmv::Feature, count);
 
-		for(std::vector<libmv::Feature>::iterator it = v.begin(); it != v.end(); it++) {
-			features[i++] = *it;
+		for (int i = 0; i < count; i++) {
+			libmv_features->features[i] = features.at(i);
 		}
 	}
+	else {
+		libmv_features->features = NULL;
+	}
 
-	libmv_features->features = features;
 	libmv_features->count = count;
-	libmv_features->margin = margin;
 
-	return (struct libmv_Features *)libmv_features;
+	return libmv_features;
 }
 
-struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data,
-                                                   int width, int height, int stride,
-                                                   int margin, int count, int min_distance)
+static void libmv_convertDetectorOptions(libmv_DetectOptions *options,
+                                         libmv::DetectOptions *detector_options)
 {
-	libmv::Feature *features = NULL;
-	struct libmv_Features *libmv_features = LIBMV_STRUCT_NEW(libmv_Features, 1);
+	switch (options->detector) {
+#define LIBMV_CONVERT(the_detector) \
+	case LIBMV_DETECTOR_ ## the_detector: \
+		detector_options->type = libmv::DetectOptions::the_detector; \
+		break;
+		LIBMV_CONVERT(FAST)
+		LIBMV_CONVERT(MORAVEC)
+		LIBMV_CONVERT(HARRIS)
+#undef LIBMV_CONVERT
+	}
+	detector_options->margin = options->margin;
+	detector_options->min_distance = options->min_distance;
+	detector_options->fast_min_trackness = options->fast_min_trackness;
+	detector_options->moravec_max_count = options->moravec_max_count;
+	detector_options->moravec_pattern = options->moravec_pattern;
+	detector_options->harris_threshold = options->harris_threshold;
+}
 
-	if (count) {
-		if (margin) {
-			data += margin * stride+margin;
-			width -= 2 * margin;
-			height -= 2 * margin;
-		}
+struct libmv_Features *libmv_detectFeaturesByte(const unsigned char *image_buffer,
+                                                int width, int height, int channels,
+                                                libmv_DetectOptions *options)
+{
+	// Prepare the image.
+	libmv::FloatImage image;
+	byteBufToImage(image_buffer, width, height, channels, &image);
 
-		features = LIBMV_STRUCT_NEW(libmv::Feature, count);
-		libmv::DetectMORAVEC(data, stride, width, height, features, &count, min_distance, NULL);
-	}
+	// Configure detector.
+	libmv::DetectOptions detector_options;
+	libmv_convertDetectorOptions(options, &detector_options);
 
-	libmv_features->count = count;
-	libmv_features->margin = margin;
-	libmv_features->features = features;
+	// Run the detector.
+	libmv::vector<libmv::Feature> detected_features;
+	libmv::Detect(image, detector_options, &detected_features);
 
-	return libmv_features;
+	// Convert result to C-API.
+	libmv_Features *result = libmv_featuresFromVector(detected_features);
+	return result;
+}
+
+struct libmv_Features *libmv_detectFeaturesFloat(const float *image_buffer,
+                                                 int width, int height, int channels,
+                                                 libmv_DetectOptions *options)
+{
+	// Prepare the image.
+	libmv::FloatImage image;
+	floatBufToImage(image_buffer, width, height, channels, &image);
+
+	// Configure detector.
+	libmv::DetectOptions detector_options;
+	libmv_convertDetectorOptions(options, &detector_options);
+
+	// Run the detector.
+	libmv::vector<libmv::Feature> detected_features;
+	libmv::Detect(image, detector_options, &detected_features);
+
+	// Convert result to C-API.
+	libmv_Features *result = libmv_featuresFromVector(detected_features);
+	return result;
 }
 
 void libmv_featuresDestroy(struct libmv_Features *libmv_features)
@@ -910,8 +958,8 @@ void libmv_getFeature(const struct libmv_Features *libmv_features, int number, d
 {
 	libmv::Feature feature = libmv_features->features[number];
 
-	*x = feature.x + libmv_features->margin;
-	*y = feature.y + libmv_features->margin;
+	*x = feature.x;
+	*y = feature.y;
 	*score = feature.score;
 	*size = feature.size;
 }
diff --git a/extern/libmv/libmv-capi.h b/extern/libmv/libmv-capi.h
index 13cc3ae..d183bc4 100644
--- a/extern/libmv/libmv-capi.h
+++ b/extern/libmv/libmv-capi.h
@@ -118,10 +118,29 @@ double libmv_reprojectionError(const struct libmv_Reconstruction *libmv_reconstr
 struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics(struct libmv_Reconstruction *libmv_Reconstruction);
 
 /* Feature detector */
-struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data, int width, int height, int stride,
-                                                int margin, int min_trackness, int min_distance);
-struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data, int width, int height, int stride,
-                                                   int margin, int count, int min_distance);
+enum {
+	LIBMV_DETECTOR_FAST,
+	LIBMV_DETECTOR_MORAVEC,
+	LIBMV_DETECTOR

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list