Blender  V2.93
detector.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2011 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #include "intern/detector.h"
21 #include "intern/image.h"
22 #include "intern/utildefines.h"
24 
25 using libmv::Detect;
27 using libmv::Feature;
28 using libmv::FloatImage;
29 
31  int count;
33 };
34 
35 namespace {
36 
37 libmv_Features* libmv_featuresFromVector(
38  const libmv::vector<Feature>& features) {
39  libmv_Features* libmv_features = LIBMV_STRUCT_NEW(libmv_Features, 1);
40  int count = features.size();
41  if (count) {
42  libmv_features->features = LIBMV_STRUCT_NEW(Feature, count);
43  for (int i = 0; i < count; i++) {
44  libmv_features->features[i] = features.at(i);
45  }
46  } else {
47  libmv_features->features = NULL;
48  }
49  libmv_features->count = count;
50  return libmv_features;
51 }
52 
53 void libmv_convertDetectorOptions(libmv_DetectOptions* options,
54  DetectOptions* detector_options) {
55  switch (options->detector) {
56 #define LIBMV_CONVERT(the_detector) \
57  case LIBMV_DETECTOR_##the_detector: \
58  detector_options->type = DetectOptions::the_detector; \
59  break;
60  LIBMV_CONVERT(FAST)
61  LIBMV_CONVERT(MORAVEC)
62  LIBMV_CONVERT(HARRIS)
63 #undef LIBMV_CONVERT
64  }
65  detector_options->margin = options->margin;
66  detector_options->min_distance = options->min_distance;
67  detector_options->fast_min_trackness = options->fast_min_trackness;
68  detector_options->moravec_max_count = options->moravec_max_count;
69  detector_options->moravec_pattern = options->moravec_pattern;
70  detector_options->harris_threshold = options->harris_threshold;
71 }
72 
73 } // namespace
74 
75 libmv_Features* libmv_detectFeaturesByte(const unsigned char* image_buffer,
76  int width,
77  int height,
78  int channels,
80  // Prepare the image.
81  FloatImage image;
82  libmv_byteBufferToFloatImage(image_buffer, width, height, channels, &image);
83 
84  // Configure detector.
85  DetectOptions detector_options;
86  libmv_convertDetectorOptions(options, &detector_options);
87 
88  // Run the detector.
89  libmv::vector<Feature> detected_features;
90  Detect(image, detector_options, &detected_features);
91 
92  // Convert result to C-API.
93  libmv_Features* result = libmv_featuresFromVector(detected_features);
94  return result;
95 }
96 
97 libmv_Features* libmv_detectFeaturesFloat(const float* image_buffer,
98  int width,
99  int height,
100  int channels,
102  // Prepare the image.
103  FloatImage image;
104  libmv_floatBufferToFloatImage(image_buffer, width, height, channels, &image);
105 
106  // Configure detector.
107  DetectOptions detector_options;
108  libmv_convertDetectorOptions(options, &detector_options);
109 
110  // Run the detector.
111  libmv::vector<Feature> detected_features;
112  Detect(image, detector_options, &detected_features);
113 
114  // Convert result to C-API.
115  libmv_Features* result = libmv_featuresFromVector(detected_features);
116  return result;
117 }
118 
119 void libmv_featuresDestroy(libmv_Features* libmv_features) {
120  if (libmv_features->features) {
121  LIBMV_STRUCT_DELETE(libmv_features->features);
122  }
123  LIBMV_STRUCT_DELETE(libmv_features);
124 }
125 
126 int libmv_countFeatures(const libmv_Features* libmv_features) {
127  return libmv_features->count;
128 }
129 
130 void libmv_getFeature(const libmv_Features* libmv_features,
131  int number,
132  double* x,
133  double* y,
134  double* score,
135  double* size) {
136  Feature& feature = libmv_features->features[number];
137  *x = feature.x;
138  *y = feature.y;
139  *score = feature.score;
140  *size = feature.size;
141 }
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
CCL_NAMESPACE_BEGIN struct Options options
libmv_Features * libmv_detectFeaturesByte(const unsigned char *image_buffer, int width, int height, int channels, libmv_DetectOptions *options)
Definition: detector.cc:75
#define LIBMV_CONVERT(the_detector)
void libmv_getFeature(const libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size)
Definition: detector.cc:130
libmv_Features * libmv_detectFeaturesFloat(const float *image_buffer, int width, int height, int channels, libmv_DetectOptions *options)
Definition: detector.cc:97
void libmv_featuresDestroy(libmv_Features *libmv_features)
Definition: detector.cc:119
int libmv_countFeatures(const libmv_Features *libmv_features)
Definition: detector.cc:126
void libmv_floatBufferToFloatImage(const float *buffer, int width, int height, int channels, FloatImage *image)
Definition: image.cc:51
void libmv_byteBufferToFloatImage(const unsigned char *buffer, int width, int height, int channels, FloatImage *image)
Definition: image.cc:36
int count
void Detect(const FloatImage &image, const DetectOptions &options, vector< Feature > *detected_features)
Definition: detect.cc:340
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
Definition: vector.h:39
Array3Df FloatImage
unsigned char * moravec_pattern
Definition: detect.h:93
double harris_threshold
Definition: detect.h:97
int fast_min_trackness
Definition: detect.h:84
float size
Definition: detect.h:59
float score
Definition: detect.h:53
float x
Definition: detect.h:46
float y
Definition: detect.h:46
Feature * features
Definition: detector.cc:32
#define LIBMV_STRUCT_NEW(type, count)
Definition: utildefines.h:53
#define LIBMV_STRUCT_DELETE(what)
Definition: utildefines.h:54