diff options
author | Joseph Mansfield <sftrabbit@gmail.com> | 2013-07-31 17:48:12 +0400 |
---|---|---|
committer | Joseph Mansfield <sftrabbit@gmail.com> | 2013-07-31 17:48:12 +0400 |
commit | c15ae082bb3bcb379c343aa770601b49c0866583 (patch) | |
tree | b29661f64f437d9f54a1d8bada9f220d422d68b1 /extern/libmv | |
parent | 81fd056d61b31046e1b201a82473eb30cfa012b3 (diff) |
Code cleanup: libmv C API
Clean up inconsistencies in the libmv C API:
- All type identifiers are libmv_TypeName
- All function identifiers libmv_functionName
- Prefer libmv_nounVerb function names (e.g. libmv_featuresDestroy)
- Match Blender code formatting rather than Google
- Spelling corrections
Code review: https://codereview.appspot.com/11494044/
Diffstat (limited to 'extern/libmv')
-rw-r--r-- | extern/libmv/libmv-capi.cc | 244 | ||||
-rw-r--r-- | extern/libmv/libmv-capi.h | 131 | ||||
-rw-r--r-- | extern/libmv/libmv-capi_stub.cc | 99 |
3 files changed, 236 insertions, 238 deletions
diff --git a/extern/libmv/libmv-capi.cc b/extern/libmv/libmv-capi.cc index 563919e1d7b..990b40df90a 100644 --- a/extern/libmv/libmv-capi.cc +++ b/extern/libmv/libmv-capi.cc @@ -62,7 +62,7 @@ # define snprintf _snprintf #endif -typedef struct libmv_Reconstruction { +struct libmv_Reconstruction { libmv::EuclideanReconstruction reconstruction; /* used for per-track average error calculation after reconstruction */ @@ -70,12 +70,12 @@ typedef struct libmv_Reconstruction { libmv::CameraIntrinsics intrinsics; double error; -} libmv_Reconstruction; +}; -typedef struct libmv_Features { +struct libmv_Features { int count, margin; libmv::Feature *features; -} libmv_Features; +}; /* ************ Logging ************ */ @@ -197,30 +197,30 @@ static void saveImage(const char *prefix, libmv::FloatImage image, int x0, int y int x, y; png_bytep *row_pointers; - row_pointers= (png_bytep*)malloc(sizeof(png_bytep)*image.Height()); + row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * image.Height()); for (y = 0; y < image.Height(); y++) { - row_pointers[y]= (png_bytep)malloc(sizeof(png_byte)*4*image.Width()); + row_pointers[y] = (png_bytep) malloc(sizeof(png_byte) * 4 * image.Width()); for (x = 0; x < image.Width(); x++) { if (x0 == x && image.Height() - y0 - 1 == y) { - row_pointers[y][x*4+0]= 255; - row_pointers[y][x*4+1]= 0; - row_pointers[y][x*4+2]= 0; - row_pointers[y][x*4+3]= 255; + row_pointers[y][x * 4 + 0] = 255; + row_pointers[y][x * 4 + 1] = 0; + row_pointers[y][x * 4 + 2] = 0; + row_pointers[y][x * 4 + 3] = 255; } else { float pixel = image(image.Height() - y - 1, x, 0); - row_pointers[y][x*4+0]= pixel*255; - row_pointers[y][x*4+1]= pixel*255; - row_pointers[y][x*4+2]= pixel*255; - row_pointers[y][x*4+3]= 255; + row_pointers[y][x * 4 + 0] = pixel * 255; + row_pointers[y][x * 4 + 1] = pixel * 255; + row_pointers[y][x * 4 + 2] = pixel * 255; + row_pointers[y][x * 4 + 3] = 255; } } } { - static int a= 0; + static int a = 0; char buf[128]; snprintf(buf, sizeof(buf), "%s_%02d.png", prefix, ++a); savePNGImage(row_pointers, image.Width(), image.Height(), 8, PNG_COLOR_TYPE_RGBA, buf); @@ -237,17 +237,17 @@ static void saveBytesImage(const char *prefix, unsigned char *data, int width, i int x, y; png_bytep *row_pointers; - row_pointers= (png_bytep*)malloc(sizeof(png_bytep)*height); + row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * height); for (y = 0; y < height; y++) { - row_pointers[y]= (png_bytep)malloc(sizeof(png_byte)*4*width); + row_pointers[y] = (png_bytep) malloc(sizeof(png_byte) * 4 * width); for (x = 0; x < width; x++) { - char pixel = data[width*y+x]; - row_pointers[y][x*4+0]= pixel; - row_pointers[y][x*4+1]= pixel; - row_pointers[y][x*4+2]= pixel; - row_pointers[y][x*4+3]= 255; + char pixel = data[width * y + x]; + row_pointers[y][x * 4 + 0] = pixel; + row_pointers[y][x * 4 + 1] = pixel; + row_pointers[y][x * 4 + 2] = pixel; + row_pointers[y][x * 4 + 3] = 255; } } @@ -267,12 +267,12 @@ static void saveBytesImage(const char *prefix, unsigned char *data, int width, i /* ************ Planar tracker ************ */ -/* TrackRegion (new planar tracker) */ -int libmv_trackRegion(const struct libmv_trackRegionOptions *options, +/* TrackRegion */ +int libmv_trackRegion(const libmv_TrackRegionOptions *options, const float *image1, int image1_width, int image1_height, const float *image2, int image2_width, int image2_height, const double *x1, const double *y1, - struct libmv_trackRegionResult *result, + libmv_TrackRegionResult *result, double *x2, double *y2) { double xx1[5], yy1[5]; @@ -292,7 +292,7 @@ int libmv_trackRegion(const struct libmv_trackRegionOptions *options, switch (options->motion_model) { #define LIBMV_CONVERT(the_model) \ - case libmv::TrackRegionOptions::the_model: \ + case libmv::TrackRegionOptions::the_model: \ track_region_options.mode = libmv::TrackRegionOptions::the_model; \ break; LIBMV_CONVERT(TRANSLATION) @@ -384,29 +384,28 @@ void libmv_samplePlanarPatch(const float *image, int width, int height, /* ************ Tracks ************ */ -libmv_Tracks *libmv_tracksNew(void) +struct libmv_Tracks *libmv_tracksNew(void) { libmv::Tracks *libmv_tracks = new libmv::Tracks(); - return (libmv_Tracks *)libmv_tracks; + return (struct libmv_Tracks *)libmv_tracks; } -void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y) +void libmv_tracksDestroy(struct libmv_Tracks *libmv_tracks) { - ((libmv::Tracks*)libmv_tracks)->Insert(image, track, x, y); + delete (libmv::Tracks*) libmv_tracks; } -void libmv_tracksDestroy(libmv_Tracks *libmv_tracks) +void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y) { - delete (libmv::Tracks*)libmv_tracks; + ((libmv::Tracks*) libmv_tracks)->Insert(image, track, x, y); } -/* ************ Reconstruction solver ************ */ +/* ************ Reconstruction ************ */ class ReconstructUpdateCallback : public libmv::ProgressUpdateCallback { public: - ReconstructUpdateCallback(reconstruct_progress_update_cb progress_update_callback, - void *callback_customdata) + ReconstructUpdateCallback(reconstruct_progress_update_cb progress_update_callback, void *callback_customdata) { progress_update_callback_ = progress_update_callback; callback_customdata_ = callback_customdata; @@ -414,7 +413,7 @@ public: void invoke(double progress, const char *message) { - if(progress_update_callback_) { + if (progress_update_callback_) { progress_update_callback_(callback_customdata_, progress, message); } } @@ -456,7 +455,7 @@ static void libmv_solveRefineIntrinsics(const libmv::Tracks &tracks, intrinsics); } -static void cameraIntrinsicsFromOptions(const libmv_cameraIntrinsicsOptions *camera_intrinsics_options, +static void cameraIntrinsicsFromOptions(const libmv_CameraIntrinsicsOptions *camera_intrinsics_options, libmv::CameraIntrinsics *camera_intrinsics) { camera_intrinsics->SetFocalLength(camera_intrinsics_options->focal_length, @@ -486,7 +485,7 @@ static libmv::Tracks getNormalizedTracks(const libmv::Tracks &tracks, const libm } static void finishReconstruction(const libmv::Tracks &tracks, const libmv::CameraIntrinsics &camera_intrinsics, - libmv_Reconstruction *libmv_reconstruction, + struct libmv_Reconstruction *libmv_reconstruction, reconstruct_progress_update_cb progress_update_callback, void *callback_customdata) { @@ -571,13 +570,13 @@ static bool selectTwoKeyframesBasedOnGRICAndVariance( return true; } -libmv_Reconstruction *libmv_solveReconstruction(const libmv_Tracks *libmv_tracks, - const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - libmv_reconstructionOptions *libmv_reconstruction_options, - reconstruct_progress_update_cb progress_update_callback, - void *callback_customdata) +struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks *libmv_tracks, + const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + libmv_ReconstructionOptions *libmv_reconstruction_options, + reconstruct_progress_update_cb progress_update_callback, + void *callback_customdata) { - libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction(); + struct libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction(); libmv::Tracks &tracks = *((libmv::Tracks *) libmv_tracks); libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction; @@ -650,16 +649,16 @@ libmv_Reconstruction *libmv_solveReconstruction(const libmv_Tracks *libmv_tracks finishReconstruction(tracks, camera_intrinsics, libmv_reconstruction, progress_update_callback, callback_customdata); - return (libmv_Reconstruction *)libmv_reconstruction; + return (struct libmv_Reconstruction *)libmv_reconstruction; } -struct libmv_Reconstruction *libmv_solveModal(const libmv_Tracks *libmv_tracks, - const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - const libmv_reconstructionOptions *libmv_reconstruction_options, - reconstruct_progress_update_cb progress_update_callback, - void *callback_customdata) +struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks *libmv_tracks, + const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + const libmv_ReconstructionOptions *libmv_reconstruction_options, + reconstruct_progress_update_cb progress_update_callback, + void *callback_customdata) { - libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction(); + struct libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction(); libmv::Tracks &tracks = *((libmv::Tracks *) libmv_tracks); libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction; @@ -697,15 +696,20 @@ struct libmv_Reconstruction *libmv_solveModal(const libmv_Tracks *libmv_tracks, finishReconstruction(tracks, camera_intrinsics, libmv_reconstruction, progress_update_callback, callback_customdata); - return (libmv_Reconstruction *)libmv_reconstruction; + return (struct libmv_Reconstruction *)libmv_reconstruction; +} + +void libmv_reconstructionDestroy(struct libmv_Reconstruction *libmv_reconstruction) +{ + delete libmv_reconstruction; } -int libmv_reporojectionPointForTrack(const libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]) +int libmv_reprojectionPointForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]) { const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction; const libmv::EuclideanPoint *point = reconstruction->PointForTrack(track); - if(point) { + if (point) { pos[0] = point->X[0]; pos[1] = point->X[2]; pos[2] = point->X[1]; @@ -732,7 +736,7 @@ static libmv::Marker ProjectMarker(const libmv::EuclideanPoint &point, return reprojected_marker; } -double libmv_reporojectionErrorForTrack(const libmv_Reconstruction *libmv_reconstruction, int track) +double libmv_reprojectionErrorForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track) { const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction; const libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics; @@ -755,13 +759,13 @@ double libmv_reporojectionErrorForTrack(const libmv_Reconstruction *libmv_recons double ex = reprojected_marker.x - markers[i].x; double ey = reprojected_marker.y - markers[i].y; - total_error += sqrt(ex*ex + ey*ey); + total_error += sqrt(ex * ex + ey * ey); } return total_error / num_reprojected; } -double libmv_reporojectionErrorForImage(const libmv_Reconstruction *libmv_reconstruction, int image) +double libmv_reprojectionErrorForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image) { const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction; const libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics; @@ -786,19 +790,19 @@ double libmv_reporojectionErrorForImage(const libmv_Reconstruction *libmv_recons double ex = reprojected_marker.x - markers[i].x; double ey = reprojected_marker.y - markers[i].y; - total_error += sqrt(ex*ex + ey*ey); + total_error += sqrt(ex * ex + ey * ey); } return total_error / num_reprojected; } -int libmv_reporojectionCameraForImage(const libmv_Reconstruction *libmv_reconstruction, +int libmv_reprojectionCameraForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4]) { const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction; const libmv::EuclideanCamera *camera = reconstruction->CameraForImage(image); - if(camera) { + if (camera) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { int l = k; @@ -809,7 +813,7 @@ int libmv_reporojectionCameraForImage(const libmv_Reconstruction *libmv_reconstr if (j == 2) mat[j][l] = -camera->R(j,k); else mat[j][l] = camera->R(j,k); } - mat[j][3]= 0.0; + mat[j][3] = 0.0; } libmv::Vec3 optical_center = -camera->R.transpose() * camera->t; @@ -818,7 +822,7 @@ int libmv_reporojectionCameraForImage(const libmv_Reconstruction *libmv_reconstr mat[3][1] = optical_center(2); mat[3][2] = optical_center(1); - mat[3][3]= 1.0; + mat[3][3] = 1.0; return 1; } @@ -826,17 +830,17 @@ int libmv_reporojectionCameraForImage(const libmv_Reconstruction *libmv_reconstr return 0; } -double libmv_reprojectionError(const libmv_Reconstruction *libmv_reconstruction) +double libmv_reprojectionError(const struct libmv_Reconstruction *libmv_reconstruction) { return libmv_reconstruction->error; } -void libmv_destroyReconstruction(libmv_Reconstruction *libmv_reconstruction) +struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics(struct libmv_Reconstruction *libmv_reconstruction) { - delete libmv_reconstruction; + return (struct libmv_CameraIntrinsics *)&libmv_reconstruction->intrinsics; } -/* ************ feature detector ************ */ +/* ************ Feature detector ************ */ struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data, int width, int height, int stride, @@ -844,24 +848,24 @@ struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data, { libmv::Feature *features = NULL; std::vector<libmv::Feature> v; - libmv_Features *libmv_features = new libmv_Features(); - int i= 0, count; + struct libmv_Features *libmv_features = new libmv_Features(); + int i = 0, count; - if(margin) { - data += margin*stride+margin; - width -= 2*margin; - height -= 2*margin; + 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(); - if(count) { - features= new libmv::Feature[count]; + if (count) { + features = new libmv::Feature[count]; for(std::vector<libmv::Feature>::iterator it = v.begin(); it != v.end(); it++) { - features[i++]= *it; + features[i++] = *it; } } @@ -869,7 +873,7 @@ struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data, libmv_features->count = count; libmv_features->margin = margin; - return (libmv_Features *)libmv_features; + return (struct libmv_Features *)libmv_features; } struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data, @@ -877,13 +881,13 @@ struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data, int margin, int count, int min_distance) { libmv::Feature *features = NULL; - libmv_Features *libmv_features = new libmv_Features; + struct libmv_Features *libmv_features = new libmv_Features; - if(count) { - if(margin) { - data += margin*stride+margin; - width -= 2*margin; - height -= 2*margin; + if (count) { + if (margin) { + data += margin * stride+margin; + width -= 2 * margin; + height -= 2 * margin; } features = new libmv::Feature[count]; @@ -897,14 +901,22 @@ struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data, return libmv_features; } -int libmv_countFeatures(const libmv_Features *libmv_features) +void libmv_featuresDestroy(struct libmv_Features *libmv_features) +{ + if (libmv_features->features) + delete [] libmv_features->features; + + delete libmv_features; +} + +int libmv_countFeatures(const struct libmv_Features *libmv_features) { return libmv_features->count; } -void libmv_getFeature(const libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size) +void libmv_getFeature(const struct libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size) { - libmv::Feature feature= libmv_features->features[number]; + libmv::Feature feature = libmv_features->features[number]; *x = feature.x + libmv_features->margin; *y = feature.y + libmv_features->margin; @@ -912,29 +924,16 @@ void libmv_getFeature(const libmv_Features *libmv_features, int number, double * *size = feature.size; } -void libmv_destroyFeatures(libmv_Features *libmv_features) -{ - if(libmv_features->features) - delete [] libmv_features->features; +/* ************ Camera intrinsics ************ */ - delete libmv_features; -} - -/* ************ camera intrinsics ************ */ - -struct libmv_CameraIntrinsics *libmv_ReconstructionExtractIntrinsics(libmv_Reconstruction *libmv_Reconstruction) -{ - return (struct libmv_CameraIntrinsics *)&libmv_Reconstruction->intrinsics; -} - -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNewEmpty(void) +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNewEmpty(void) { libmv::CameraIntrinsics *camera_intrinsics = new libmv::CameraIntrinsics(); return (struct libmv_CameraIntrinsics *) camera_intrinsics; } -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options) +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options) { libmv::CameraIntrinsics *camera_intrinsics = new libmv::CameraIntrinsics(); @@ -943,23 +942,23 @@ struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(const libmv_cameraIntri return (struct libmv_CameraIntrinsics *) camera_intrinsics; } -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(const libmv_CameraIntrinsics *libmvIntrinsics) +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsCopy(const libmv_CameraIntrinsics *libmvIntrinsics) { libmv::CameraIntrinsics *orig_intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics; - libmv::CameraIntrinsics *new_intrinsics= new libmv::CameraIntrinsics(*orig_intrinsics); + libmv::CameraIntrinsics *new_intrinsics = new libmv::CameraIntrinsics(*orig_intrinsics); return (struct libmv_CameraIntrinsics *) new_intrinsics; } -void libmv_CameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmvIntrinsics) +void libmv_cameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmvIntrinsics) { libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics; delete intrinsics; } -void libmv_CameraIntrinsicsUpdate(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - libmv_CameraIntrinsics *libmv_intrinsics) +void libmv_cameraIntrinsicsUpdate(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + struct libmv_CameraIntrinsics *libmv_intrinsics) { libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics; @@ -997,15 +996,16 @@ void libmv_CameraIntrinsicsUpdate(const libmv_cameraIntrinsicsOptions *libmv_cam } } -void libmv_CameraIntrinsicsSetThreads(libmv_CameraIntrinsics *libmv_intrinsics, int threads) +void libmv_cameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics *libmv_intrinsics, int threads) { libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics; camera_intrinsics->SetThreads(threads); } -void libmv_CameraIntrinsicsExtract(const libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length, - double *principal_x, double *principal_y, double *k1, double *k2, double *k3, int *width, int *height) +void libmv_cameraIntrinsicsExtract(const struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length, + double *principal_x, double *principal_y, double *k1, double *k2, double *k3, + int *width, int *height) { libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics; @@ -1016,40 +1016,42 @@ void libmv_CameraIntrinsicsExtract(const libmv_CameraIntrinsics *libmv_intrinsic *k2 = camera_intrinsics->k2(); } -void libmv_CameraIntrinsicsUndistortByte(const libmv_CameraIntrinsics *libmv_intrinsics, - unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics, + unsigned char *src, unsigned char *dst, int width, int height, + float overscan, int channels) { libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics; camera_intrinsics->Undistort(src, dst, width, height, overscan, channels); } -void libmv_CameraIntrinsicsUndistortFloat(const libmv_CameraIntrinsics *libmvIntrinsics, - float *src, float *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics *libmvIntrinsics, + float *src, float *dst, int width, int height, + float overscan, int channels) { libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics; intrinsics->Undistort(src, dst, width, height, overscan, channels); } -void libmv_CameraIntrinsicsDistortByte(const libmv_CameraIntrinsics *libmvIntrinsics, - unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmvIntrinsics, + unsigned char *src, unsigned char *dst, int width, int height, + float overscan, int channels) { libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics; intrinsics->Distort(src, dst, width, height, overscan, channels); } -void libmv_CameraIntrinsicsDistortFloat(const libmv_CameraIntrinsics *libmvIntrinsics, - float *src, float *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmvIntrinsics, + float *src, float *dst, int width, int height, + float overscan, int channels) { libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics; intrinsics->Distort(src, dst, width, height, overscan, channels); } -/* ************ utils ************ */ - -void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, +void libmv_cameraIntrinsicsApply(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, double x, double y, double *x1, double *y1) { libmv::CameraIntrinsics camera_intrinsics; @@ -1063,7 +1065,7 @@ void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_came } } -void libmv_InvertCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, +void libmv_cameraIntrinsicsInvert(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, double x, double y, double *x1, double *y1) { libmv::CameraIntrinsics camera_intrinsics; diff --git a/extern/libmv/libmv-capi.h b/extern/libmv/libmv-capi.h index beac3e85468..7c91881fe71 100644 --- a/extern/libmv/libmv-capi.h +++ b/extern/libmv/libmv-capi.h @@ -41,8 +41,8 @@ void libmv_initLogging(const char *argv0); void libmv_startDebugLogging(void); void libmv_setLoggingVerbosity(int verbosity); -/* TrackRegion (new planar tracker) */ -struct libmv_trackRegionOptions { +/* Planar tracker */ +typedef struct libmv_TrackRegionOptions { int motion_model; int num_iterations; int use_brute; @@ -50,21 +50,20 @@ struct libmv_trackRegionOptions { double minimum_correlation; double sigma; float *image1_mask; -}; +} libmv_TrackRegionOptions; -struct libmv_trackRegionResult { +typedef struct libmv_TrackRegionResult { int termination; const char *termination_reason; double correlation; -}; +} libmv_TrackRegionResult; -int libmv_trackRegion(const struct libmv_trackRegionOptions *options, +int libmv_trackRegion(const libmv_TrackRegionOptions *options, const float *image1, int image1_width, int image1_height, const float *image2, int image2_width, int image2_height, const double *x1, const double *y1, - struct libmv_trackRegionResult *result, + libmv_TrackRegionResult *result, double *x2, double *y2); - void libmv_samplePlanarPatch(const float *image, int width, int height, int channels, const double *xs, const double *ys, int num_samples_x, int num_samples_y, @@ -73,25 +72,24 @@ void libmv_samplePlanarPatch(const float *image, int width, int height, /* Tracks */ struct libmv_Tracks *libmv_tracksNew(void); -void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y); void libmv_tracksDestroy(struct libmv_Tracks *libmv_tracks); +void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y); -/* Reconstruction solver */ - +/* Reconstruction */ #define LIBMV_REFINE_FOCAL_LENGTH (1 << 0) #define LIBMV_REFINE_PRINCIPAL_POINT (1 << 1) #define LIBMV_REFINE_RADIAL_DISTORTION_K1 (1 << 2) #define LIBMV_REFINE_RADIAL_DISTORTION_K2 (1 << 4) -typedef struct libmv_cameraIntrinsicsOptions { +typedef struct libmv_CameraIntrinsicsOptions { double focal_length; double principal_point_x, principal_point_y; double k1, k2, k3; double p1, p2; int image_width, image_height; -} libmv_cameraIntrinsicsOptions; +} libmv_CameraIntrinsicsOptions; -typedef struct libmv_reconstructionOptions { +typedef struct libmv_ReconstructionOptions { int select_keyframes; int keyframe1, keyframe2; @@ -99,72 +97,67 @@ typedef struct libmv_reconstructionOptions { double success_threshold; int use_fallback_reconstruction; -} libmv_reconstructionOptions; +} libmv_ReconstructionOptions; typedef void (*reconstruct_progress_update_cb) (void *customdata, double progress, const char *message); struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks *libmv_tracks, - const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - libmv_reconstructionOptions *libmv_reconstruction_options, - reconstruct_progress_update_cb progress_update_callback, - void *callback_customdata); + const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + libmv_ReconstructionOptions *libmv_reconstruction_options, + reconstruct_progress_update_cb progress_update_callback, + void *callback_customdata); struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks *libmv_tracks, - const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - const libmv_reconstructionOptions *libmv_reconstruction_options, - reconstruct_progress_update_cb progress_update_callback, - void *callback_customdata); -int libmv_reporojectionPointForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]); -double libmv_reporojectionErrorForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track); -double libmv_reporojectionErrorForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image); -int libmv_reporojectionCameraForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4]); + const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + const libmv_ReconstructionOptions *libmv_reconstruction_options, + reconstruct_progress_update_cb progress_update_callback, + void *callback_customdata); +void libmv_reconstructionDestroy(struct libmv_Reconstruction *libmv_reconstruction); +int libmv_reprojectionPointForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]); +double libmv_reprojectionErrorForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track); +double libmv_reprojectionErrorForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image); +int libmv_reprojectionCameraForImage(const struct libmv_Reconstruction *libmv_reconstruction, + int image, double mat[4][4]); double libmv_reprojectionError(const struct libmv_Reconstruction *libmv_reconstruction); -void libmv_destroyReconstruction(struct libmv_Reconstruction *libmv_reconstruction); +struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics(struct libmv_Reconstruction *libmv_Reconstruction); -/* feature detector */ +/* 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); + 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); + int margin, int count, int min_distance); +void libmv_featuresDestroy(struct libmv_Features *libmv_features); int libmv_countFeatures(const struct libmv_Features *libmv_features); -void libmv_getFeature(const struct libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size); -void libmv_destroyFeatures(struct libmv_Features *libmv_features); - -/* camera intrinsics */ -struct libmv_CameraIntrinsics *libmv_ReconstructionExtractIntrinsics(struct libmv_Reconstruction *libmv_Reconstruction); - -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNewEmpty(void); - -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options); - -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(const struct libmv_CameraIntrinsics *libmv_intrinsics); - -void libmv_CameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmv_intrinsics); - -void libmv_CameraIntrinsicsUpdate(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, +void libmv_getFeature(const struct libmv_Features *libmv_features, int number, double *x, double *y, double *score, + double *size); + +/* Camera intrinsics */ +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNewEmpty(void); +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew( + const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options); +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsCopy(const struct libmv_CameraIntrinsics *libmv_intrinsics); +void libmv_cameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmv_intrinsics); +void libmv_cameraIntrinsicsUpdate(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, struct libmv_CameraIntrinsics *libmv_intrinsics); - -void libmv_CameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics *libmv_intrinsics, int threads); - -void libmv_CameraIntrinsicsExtract(const struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length, - double *principal_x, double *principal_y, double *k1, double *k2, double *k3, int *width, int *height); - -void libmv_CameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics, - unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels); - -void libmv_CameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics, - float *src, float *dst, int width, int height, float overscan, int channels); - -void libmv_CameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics, - unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels); - -void libmv_CameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics, - float *src, float *dst, int width, int height, float overscan, int channels); - -/* utils */ -void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - double x, double y, double *x1, double *y1); -void libmv_InvertCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, - double x, double y, double *x1, double *y1); +void libmv_cameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics *libmv_intrinsics, int threads); +void libmv_cameraIntrinsicsExtract(const struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length, + double *principal_x, double *principal_y, double *k1, double *k2, double *k3, + int *width, int *height); +void libmv_cameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics, + unsigned char *src, unsigned char *dst, int width, int height, + float overscan, int channels); +void libmv_cameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics, + float *src, float *dst, int width, int height, + float overscan, int channels); +void libmv_cameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics, + unsigned char *src, unsigned char *dst, int width, int height, + float overscan, int channels); +void libmv_cameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics, + float *src, float *dst, int width, int height, + float overscan, int channels); +void libmv_cameraIntrinsicsApply(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + double x, double y, double *x1, double *y1); +void libmv_cameraIntrinsicsInvert(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, + double x, double y, double *x1, double *y1); #ifdef __cplusplus } diff --git a/extern/libmv/libmv-capi_stub.cc b/extern/libmv/libmv-capi_stub.cc index 4bc2b18081a..36977eb58ba 100644 --- a/extern/libmv/libmv-capi_stub.cc +++ b/extern/libmv/libmv-capi_stub.cc @@ -48,11 +48,11 @@ void libmv_setLoggingVerbosity(int /*verbosity*/) /* ************ Planar tracker ************ */ /* TrackRegion (new planar tracker) */ -int libmv_trackRegion(const struct libmv_trackRegionOptions * /*options*/, +int libmv_trackRegion(const libmv_TrackRegionOptions * /*options*/, const float * /*image1*/, int /*image1_width*/, int /*image1_height*/, const float * /*image2*/, int /*image2_width*/, int /*image2_height*/, const double *x1, const double *y1, - struct libmv_trackRegionResult *result, + libmv_TrackRegionResult *result, double *x2, double *y2) { /* Convert to doubles for the libmv api. The four corners and the center. */ @@ -79,7 +79,8 @@ void libmv_samplePlanarPatch(const float *image, int width, int height, /* ************ Tracks ************ */ -libmv_Tracks *libmv_tracksNew(void) { +struct libmv_Tracks *libmv_tracksNew(void) +{ return NULL; } @@ -88,73 +89,72 @@ void libmv_tracksInsert(struct libmv_Tracks * /*libmv_tracks*/, int /*image*/, { } -void libmv_tracksDestroy(libmv_Tracks * /*libmv_tracks*/) +void libmv_tracksDestroy(struct libmv_Tracks * /*libmv_tracks*/) { } /* ************ Reconstruction solver ************ */ -libmv_Reconstruction *libmv_solveReconstruction(const libmv_Tracks * /*libmv_tracks*/, - const libmv_cameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/, - libmv_reconstructionOptions * /*libmv_reconstruction_options*/, - reconstruct_progress_update_cb /*progress_update_callback*/, - void * /*callback_customdata*/) +struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks * /*libmv_tracks*/, + const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/, + libmv_ReconstructionOptions * /*libmv_reconstruction_options*/, + reconstruct_progress_update_cb /*progress_update_callback*/, + void * /*callback_customdata*/) { return NULL; } struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks * /*libmv_tracks*/, - const libmv_cameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/, - const libmv_reconstructionOptions * /*libmv_reconstruction_options*/, - reconstruct_progress_update_cb /*progress_update_callback*/, - void * /*callback_customdata*/) + const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/, + const libmv_ReconstructionOptions * /*libmv_reconstruction_options*/, + reconstruct_progress_update_cb /*progress_update_callback*/, + void * /*callback_customdata*/) { return NULL; } -int libmv_reporojectionPointForTrack(const libmv_Reconstruction * /*libmv_reconstruction*/, +int libmv_reprojectionPointForTrack(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*track*/, double /*pos*/[3]) { return 0; } -double libmv_reporojectionErrorForTrack(const libmv_Reconstruction * /*libmv_reconstruction*/, int /*track*/) +double libmv_reprojectionErrorForTrack(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*track*/) { return 0.0; } -double libmv_reporojectionErrorForImage(const libmv_Reconstruction * /*libmv_reconstruction*/, int /*image*/) +double libmv_reprojectionErrorForImage(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*image*/) { return 0.0; } -int libmv_reporojectionCameraForImage(const libmv_Reconstruction * /*libmv_reconstruction*/, int /*image*/, +int libmv_reprojectionCameraForImage(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*image*/, double /*mat*/[4][4]) { return 0; } -double libmv_reprojectionError(const libmv_Reconstruction * /*libmv_reconstruction*/) +double libmv_reprojectionError(const struct libmv_Reconstruction * /*libmv_reconstruction*/) { return 0.0; } -void libmv_destroyReconstruction(libmv_Reconstruction * /*libmv_reconstruction*/) +void libmv_reconstructionDestroy(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_detectFeaturesFAST(const unsigned char * /*data*/, int /*width*/, int /*height*/, + int /*stride*/, int /*margin*/, int /*min_trackness*/, + int /*min_distance*/) { return NULL; } -struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char * /*data*/, - int /*width*/, int /*height*/, int /*stride*/, - int /*margin*/, int /*count*/, 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*/) { return NULL; } @@ -173,49 +173,50 @@ void libmv_getFeature(const struct libmv_Features * /*libmv_features*/, int /*nu *size = 0.0; } -void libmv_destroyFeatures(struct libmv_Features * /*libmv_features*/) +void libmv_featuresDestroy(struct libmv_Features * /*libmv_features*/) { } /* ************ camera intrinsics ************ */ -struct libmv_CameraIntrinsics *libmv_ReconstructionExtractIntrinsics( - struct libmv_Reconstruction * /*libmv_Reconstruction*/) +struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics( + struct libmv_Reconstruction * /*libmv_reconstruction*/) { return NULL; } -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNewEmpty(void) +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNewEmpty(void) { return NULL; } -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(const libmv_cameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/) +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew( + const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/) { return NULL; } -struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(const struct libmv_CameraIntrinsics * /*libmvIntrinsics*/) +struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsCopy(const libmv_CameraIntrinsics * /*libmvIntrinsics*/) { return NULL; } -void libmv_CameraIntrinsicsDestroy(struct libmv_CameraIntrinsics * /*libmvIntrinsics*/) +void libmv_cameraIntrinsicsDestroy(struct libmv_CameraIntrinsics * /*libmvIntrinsics*/) { } -void libmv_CameraIntrinsicsUpdate(const libmv_cameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/, - libmv_CameraIntrinsics * /*libmv_intrinsics*/) +void libmv_cameraIntrinsicsUpdate(const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/, + struct libmv_CameraIntrinsics * /*libmv_intrinsics*/) { } -void libmv_CameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, int /*threads*/) +void libmv_cameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, int /*threads*/) { } -void libmv_CameraIntrinsicsExtract(const struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, double * focal_length, - double * principal_x, double *principal_y, double *k1, double *k2, double *k3, - int *width, int *height) +void libmv_cameraIntrinsicsExtract(const struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, double * focal_length, + double * principal_x, double *principal_y, double *k1, double *k2, double *k3, + int *width, int *height) { *focal_length = 1.0; *principal_x = 0.0; @@ -226,33 +227,35 @@ void libmv_CameraIntrinsicsExtract(const struct libmv_CameraIntrinsics * /*libmv *height = 0.0; } -void libmv_CameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, - unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, + unsigned char *src, unsigned char *dst, int width, int height, + float overscan, int channels) { memcpy(dst, src, channels * width * height * sizeof(unsigned char)); } -void libmv_CameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics * /*libmvIntrinsics*/, - float *src, float *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics * /*libmvIntrinsics*/, + float *src, float *dst, int width, int height, float overscan, int channels) { memcpy(dst, src, channels * width * height * sizeof(float)); } -void libmv_CameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmvIntrinsics, - unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmvIntrinsics, + unsigned char *src, unsigned char *dst, int width, int height, + float overscan, int channels) { memcpy(dst, src, channels * width * height * sizeof(unsigned char)); } -void libmv_CameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmvIntrinsics, - float *src, float *dst, int width, int height, float overscan, int channels) +void libmv_cameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmvIntrinsics, + float *src, float *dst, int width, int height, float overscan, int channels) { memcpy(dst, src, channels * width * height * sizeof(float)); } /* ************ utils ************ */ -void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, +void libmv_cameraIntrinsicsApply(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, double x, double y, double *x1, double *y1) { double focal_length = libmv_camera_intrinsics_options->focal_length; @@ -263,7 +266,7 @@ void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_came *y1 = y * focal_length + principal_y; } -void libmv_InvertCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options, +void libmv_cameraIntrinsicsInvert(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options, double x, double y, double *x1, double *y1) { double focal_length = libmv_camera_intrinsics_options->focal_length; |