Blender V4.3
detector.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "intern/detector.h"
6#include "intern/image.h"
9
10using libmv::Detect;
12using libmv::Feature;
14
19
20namespace {
21
22libmv_Features* libmv_featuresFromVector(
23 const libmv::vector<Feature>& features) {
25 int count = features.size();
26 if (count) {
27 libmv_features->features = LIBMV_STRUCT_NEW(Feature, count);
28 for (int i = 0; i < count; i++) {
29 libmv_features->features[i] = features.at(i);
30 }
31 } else {
32 libmv_features->features = NULL;
33 }
34 libmv_features->count = count;
35 return libmv_features;
36}
37
38void libmv_convertDetectorOptions(libmv_DetectOptions* options,
39 DetectOptions* detector_options) {
40 switch (options->detector) {
41#define LIBMV_CONVERT(the_detector) \
42 case LIBMV_DETECTOR_##the_detector: \
43 detector_options->type = DetectOptions::the_detector; \
44 break;
45 LIBMV_CONVERT(FAST)
46 LIBMV_CONVERT(MORAVEC)
47 LIBMV_CONVERT(HARRIS)
48#undef LIBMV_CONVERT
49 }
50 detector_options->margin = options->margin;
51 detector_options->min_distance = options->min_distance;
52 detector_options->fast_min_trackness = options->fast_min_trackness;
53 detector_options->moravec_max_count = options->moravec_max_count;
54 detector_options->moravec_pattern = options->moravec_pattern;
55 detector_options->harris_threshold = options->harris_threshold;
56}
57
58} // namespace
59
60libmv_Features* libmv_detectFeaturesByte(const unsigned char* image_buffer,
61 int width,
62 int height,
63 int channels,
65 // Prepare the image.
66 FloatImage image;
67 libmv_byteBufferToFloatImage(image_buffer, width, height, channels, &image);
68
69 // Configure detector.
70 DetectOptions detector_options;
71 libmv_convertDetectorOptions(options, &detector_options);
72
73 // Run the detector.
74 libmv::vector<Feature> detected_features;
75 Detect(image, detector_options, &detected_features);
76
77 // Convert result to C-API.
78 libmv_Features* result = libmv_featuresFromVector(detected_features);
79 return result;
80}
81
82libmv_Features* libmv_detectFeaturesFloat(const float* image_buffer,
83 int width,
84 int height,
85 int channels,
87 // Prepare the image.
88 FloatImage image;
89 libmv_floatBufferToFloatImage(image_buffer, width, height, channels, &image);
90
91 // Configure detector.
92 DetectOptions detector_options;
93 libmv_convertDetectorOptions(options, &detector_options);
94
95 // Run the detector.
96 libmv::vector<Feature> detected_features;
97 Detect(image, detector_options, &detected_features);
98
99 // Convert result to C-API.
100 libmv_Features* result = libmv_featuresFromVector(detected_features);
101 return result;
102}
103
105 if (libmv_features->features) {
106 LIBMV_STRUCT_DELETE(libmv_features->features);
107 }
108 LIBMV_STRUCT_DELETE(libmv_features);
109}
110
111int libmv_countFeatures(const libmv_Features* libmv_features) {
112 return libmv_features->count;
113}
114
115void libmv_getFeature(const libmv_Features* libmv_features,
116 int number,
117 double* x,
118 double* y,
119 double* score,
120 double* size) {
121 Feature& feature = libmv_features->features[number];
122 *x = feature.x;
123 *y = feature.y;
124 *score = feature.score;
125 *size = feature.size;
126}
3D array (row, column, channel).
Definition array_nd.h:332
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
CCL_NAMESPACE_BEGIN struct Options options
#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:115
libmv_Features * libmv_detectFeaturesByte(const unsigned char *image_buffer, int width, int height, int channels, libmv_DetectOptions *options)
Definition detector.cc:60
void libmv_featuresDestroy(libmv_Features *libmv_features)
Definition detector.cc:104
libmv_Features * libmv_detectFeaturesFloat(const float *image_buffer, int width, int height, int channels, libmv_DetectOptions *options)
Definition detector.cc:82
int libmv_countFeatures(const libmv_Features *libmv_features)
Definition detector.cc:111
#define NULL
int count
void libmv_floatBufferToFloatImage(const float *buffer, int width, int height, int channels, FloatImage *image)
void libmv_byteBufferToFloatImage(const unsigned char *buffer, int width, int height, int channels, FloatImage *image)
void Detect(const FloatImage &image, const DetectOptions &options, vector< Feature > *detected_features)
Definition detect.cc:347
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
unsigned char * moravec_pattern
Definition detect.h:93
double harris_threshold
Definition detect.h:97
float size
Definition detect.h:59
float score
Definition detect.h:53
Feature * features
Definition detector.cc:17
#define LIBMV_STRUCT_NEW(type, count)
Definition utildefines.h:50
#define LIBMV_STRUCT_DELETE(what)
Definition utildefines.h:51