Speedup track preview widget for byte images
[blender.git] / extern / libmv / libmv-capi.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2011 Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation,
22  *                 Sergey Sharybin
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #ifndef LIBMV_C_API_H
28 #define LIBMV_C_API_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 struct libmv_Tracks;
35 struct libmv_Reconstruction;
36 struct libmv_Features;
37 struct libmv_CameraIntrinsics;
38
39 /* Logging */
40 void libmv_initLogging(const char *argv0);
41 void libmv_startDebugLogging(void);
42 void libmv_setLoggingVerbosity(int verbosity);
43
44 /* Planar tracker */
45 typedef struct libmv_TrackRegionOptions {
46         int motion_model;
47         int num_iterations;
48         int use_brute;
49         int use_normalization;
50         double minimum_correlation;
51         double sigma;
52         float *image1_mask;
53 } libmv_TrackRegionOptions;
54
55 typedef struct libmv_TrackRegionResult {
56         int termination;
57         const char *termination_reason;
58         double correlation;
59 } libmv_TrackRegionResult;
60
61 int libmv_trackRegion(const libmv_TrackRegionOptions *options,
62                       const float *image1, int image1_width, int image1_height,
63                       const float *image2, int image2_width, int image2_height,
64                       const double *x1, const double *y1,
65                       libmv_TrackRegionResult *result,
66                       double *x2, double *y2);
67 void libmv_samplePlanarPatch(const float *image,
68                              int width, int height,
69                              int channels,
70                              const double *xs, const double *ys,
71                              int num_samples_x, int num_samples_y,
72                              const float *mask,
73                              float *patch,
74                              double *warped_position_x, double *warped_position_y);
75 void libmv_samplePlanarPatchByte(const unsigned char *image,
76                                  int width, int height,
77                                  int channels,
78                                  const double *xs, const double *ys,
79                                  int num_samples_x, int num_samples_y,
80                                  const float *mask,
81                                  unsigned char *patch,
82                                  double *warped_position_x, double *warped_position_y);
83
84 /* Tracks */
85 struct libmv_Tracks *libmv_tracksNew(void);
86 void libmv_tracksDestroy(struct libmv_Tracks *libmv_tracks);
87 void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y, double weight);
88
89 /* Reconstruction */
90 #define LIBMV_REFINE_FOCAL_LENGTH          (1 << 0)
91 #define LIBMV_REFINE_PRINCIPAL_POINT       (1 << 1)
92 #define LIBMV_REFINE_RADIAL_DISTORTION_K1  (1 << 2)
93 #define LIBMV_REFINE_RADIAL_DISTORTION_K2  (1 << 4)
94
95 typedef struct libmv_CameraIntrinsicsOptions {
96         double focal_length;
97         double principal_point_x, principal_point_y;
98         double k1, k2, k3;
99         double p1, p2;
100         int image_width, image_height;
101 } libmv_CameraIntrinsicsOptions;
102
103 typedef struct libmv_ReconstructionOptions {
104         int select_keyframes;
105         int keyframe1, keyframe2;
106
107         int refine_intrinsics;
108 } libmv_ReconstructionOptions;
109
110 typedef void (*reconstruct_progress_update_cb) (void *customdata, double progress, const char *message);
111
112 struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks *libmv_tracks,
113                 const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
114                 libmv_ReconstructionOptions *libmv_reconstruction_options,
115                 reconstruct_progress_update_cb progress_update_callback,
116                 void *callback_customdata);
117 struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks *libmv_tracks,
118                 const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
119                 const libmv_ReconstructionOptions *libmv_reconstruction_options,
120                 reconstruct_progress_update_cb progress_update_callback,
121                 void *callback_customdata);
122 void libmv_reconstructionDestroy(struct libmv_Reconstruction *libmv_reconstruction);
123 int libmv_reprojectionPointForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]);
124 double libmv_reprojectionErrorForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track);
125 double libmv_reprojectionErrorForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image);
126 int libmv_reprojectionCameraForImage(const struct libmv_Reconstruction *libmv_reconstruction,
127                                      int image, double mat[4][4]);
128 double libmv_reprojectionError(const struct libmv_Reconstruction *libmv_reconstruction);
129 struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics(struct libmv_Reconstruction *libmv_Reconstruction);
130
131 /* Feature detector */
132 enum {
133         LIBMV_DETECTOR_FAST,
134         LIBMV_DETECTOR_MORAVEC,
135         LIBMV_DETECTOR_HARRIS,
136 };
137
138 typedef struct libmv_DetectOptions {
139   int detector;
140   int margin;
141   int min_distance;
142   int fast_min_trackness;
143   int moravec_max_count;
144   unsigned char *moravec_pattern;
145   double harris_threshold;
146 } libmv_DetectOptions;
147
148 struct libmv_Features *libmv_detectFeaturesByte(const unsigned char *image_buffer,
149                                                 int width, int height, int channels,
150                                                 libmv_DetectOptions *options);
151 struct libmv_Features *libmv_detectFeaturesFloat(const float *image_buffer,
152                                                  int width, int height, int channels,
153                                                  libmv_DetectOptions *options);
154
155 void libmv_featuresDestroy(struct libmv_Features *libmv_features);
156 int libmv_countFeatures(const struct libmv_Features *libmv_features);
157 void libmv_getFeature(const struct libmv_Features *libmv_features, int number, double *x, double *y, double *score,
158                       double *size);
159
160 /* Camera intrinsics */
161 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNewEmpty(void);
162 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew(
163                 const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options);
164 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsCopy(const struct libmv_CameraIntrinsics *libmv_intrinsics);
165 void libmv_cameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmv_intrinsics);
166 void libmv_cameraIntrinsicsUpdate(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
167                                   struct libmv_CameraIntrinsics *libmv_intrinsics);
168 void libmv_cameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics *libmv_intrinsics, int threads);
169 void libmv_cameraIntrinsicsExtract(const struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length,
170                                    double *principal_x, double *principal_y, double *k1, double *k2, double *k3,
171                                    int *width, int *height);
172 void libmv_cameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics,
173                                          unsigned char *src, unsigned char *dst, int width, int height,
174                                          float overscan, int channels);
175 void libmv_cameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics,
176                                           float *src, float *dst, int width, int height,
177                                           float overscan, int channels);
178 void libmv_cameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics,
179                                        unsigned char *src, unsigned char *dst, int width, int height,
180                                        float overscan, int channels);
181 void libmv_cameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics,
182                                         float *src, float *dst, int width, int height,
183                                         float overscan, int channels);
184 void libmv_cameraIntrinsicsApply(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
185                                  double x, double y, double *x1, double *y1);
186 void libmv_cameraIntrinsicsInvert(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
187                                   double x, double y, double *x1, double *y1);
188
189 void libmv_homography2DFromCorrespondencesEuc(double (*x1)[2], double (*x2)[2], int num_points, double H[3][3]);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif // LIBMV_C_API_H