diff options
Diffstat (limited to 'intern/libmv/libmv/simple_pipeline/camera_intrinsics_impl.h')
-rw-r--r-- | intern/libmv/libmv/simple_pipeline/camera_intrinsics_impl.h | 143 |
1 files changed, 70 insertions, 73 deletions
diff --git a/intern/libmv/libmv/simple_pipeline/camera_intrinsics_impl.h b/intern/libmv/libmv/simple_pipeline/camera_intrinsics_impl.h index e1b53992dfd..c8c4700f5c6 100644 --- a/intern/libmv/libmv/simple_pipeline/camera_intrinsics_impl.h +++ b/intern/libmv/libmv/simple_pipeline/camera_intrinsics_impl.h @@ -25,11 +25,11 @@ namespace { // FIXME: C++ templates limitations makes thing complicated, // but maybe there is a simpler method. struct ApplyIntrinsicsFunction { - ApplyIntrinsicsFunction(const CameraIntrinsics &intrinsics, + ApplyIntrinsicsFunction(const CameraIntrinsics& intrinsics, double x, double y, - double *warp_x, - double *warp_y) { + double* warp_x, + double* warp_y) { double normalized_x, normalized_y; intrinsics.ImageSpaceToNormalized(x, y, &normalized_x, &normalized_y); intrinsics.ApplyIntrinsics(normalized_x, normalized_y, warp_x, warp_y); @@ -37,14 +37,15 @@ struct ApplyIntrinsicsFunction { }; struct InvertIntrinsicsFunction { - InvertIntrinsicsFunction(const CameraIntrinsics &intrinsics, + InvertIntrinsicsFunction(const CameraIntrinsics& intrinsics, double x, double y, - double *warp_x, - double *warp_y) { + double* warp_x, + double* warp_y) { double normalized_x, normalized_y; intrinsics.InvertIntrinsics(x, y, &normalized_x, &normalized_y); - intrinsics.NormalizedToImageSpace(normalized_x, normalized_y, warp_x, warp_y); + intrinsics.NormalizedToImageSpace( + normalized_x, normalized_y, warp_x, warp_y); } }; @@ -53,18 +54,18 @@ struct InvertIntrinsicsFunction { namespace internal { // TODO(MatthiasF): downsample lookup -template<typename WarpFunction> -void LookupWarpGrid::Compute(const CameraIntrinsics &intrinsics, +template <typename WarpFunction> +void LookupWarpGrid::Compute(const CameraIntrinsics& intrinsics, int width, int height, double overscan) { - double w = (double) width / (1.0 + overscan); - double h = (double) height / (1.0 + overscan); - double aspx = (double) w / intrinsics.image_width(); - double aspy = (double) h / intrinsics.image_height(); + double w = (double)width / (1.0 + overscan); + double h = (double)height / (1.0 + overscan); + double aspx = (double)w / intrinsics.image_width(); + double aspy = (double)h / intrinsics.image_height(); #if defined(_OPENMP) -# pragma omp parallel for schedule(static) num_threads(threads_) \ - if (threads_ > 1 && height > 100) +# pragma omp parallel for schedule(static) \ + num_threads(threads_) if (threads_ > 1 && height > 100) #endif for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { @@ -76,40 +77,47 @@ void LookupWarpGrid::Compute(const CameraIntrinsics &intrinsics, warp_y = warp_y * aspy + 0.5 * overscan * h; int ix = int(warp_x), iy = int(warp_y); int fx = round((warp_x - ix) * 256), fy = round((warp_y - iy) * 256); - if (fx == 256) { fx = 0; ix++; } // NOLINT - if (fy == 256) { fy = 0; iy++; } // NOLINT + if (fx == 256) { + fx = 0; + ix++; + } // NOLINT + if (fy == 256) { + fy = 0; + iy++; + } // NOLINT // Use nearest border pixel - if (ix < 0) { ix = 0, fx = 0; } // NOLINT - if (iy < 0) { iy = 0, fy = 0; } // NOLINT - if (ix >= width - 2) ix = width - 2; - if (iy >= height - 2) iy = height - 2; - - Offset offset = { (short) (ix - x), - (short) (iy - y), - (unsigned char) fx, - (unsigned char) fy }; + if (ix < 0) { + ix = 0, fx = 0; + } // NOLINT + if (iy < 0) { + iy = 0, fy = 0; + } // NOLINT + if (ix >= width - 2) + ix = width - 2; + if (iy >= height - 2) + iy = height - 2; + + Offset offset = {(short)(ix - x), + (short)(iy - y), + (unsigned char)fx, + (unsigned char)fy}; offset_[y * width + x] = offset; } } } -template<typename WarpFunction> -void LookupWarpGrid::Update(const CameraIntrinsics &intrinsics, +template <typename WarpFunction> +void LookupWarpGrid::Update(const CameraIntrinsics& intrinsics, int width, int height, double overscan) { - if (width_ != width || - height_ != height || - overscan_ != overscan) { + if (width_ != width || height_ != height || overscan_ != overscan) { Reset(); } if (offset_ == NULL) { offset_ = new Offset[width * height]; - Compute<WarpFunction>(intrinsics, - width, - height, - overscan); + Compute<WarpFunction>(intrinsics, width, height, overscan); } width_ = width; @@ -118,29 +126,30 @@ void LookupWarpGrid::Update(const CameraIntrinsics &intrinsics, } // TODO(MatthiasF): cubic B-Spline image sampling, bilinear lookup -template<typename PixelType> -void LookupWarpGrid::Apply(const PixelType *input_buffer, +template <typename PixelType> +void LookupWarpGrid::Apply(const PixelType* input_buffer, int width, int height, int channels, - PixelType *output_buffer) { + PixelType* output_buffer) { #if defined(_OPENMP) -# pragma omp parallel for schedule(static) num_threads(threads_) \ - if (threads_ > 1 && height > 100) +# pragma omp parallel for schedule(static) \ + num_threads(threads_) if (threads_ > 1 && height > 100) #endif for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Offset offset = offset_[y * width + x]; - const int pixel_index = ((y + offset.iy) * width + - (x + offset.ix)) * channels; - const PixelType *s = &input_buffer[pixel_index]; + const int pixel_index = + ((y + offset.iy) * width + (x + offset.ix)) * channels; + const PixelType* s = &input_buffer[pixel_index]; for (int i = 0; i < channels; i++) { output_buffer[(y * width + x) * channels + i] = - ((s[i] * (256 - offset.fx) + - s[channels + i] * offset.fx) * (256 - offset.fy) + - (s[width * channels + i] * (256 - offset.fx) + - s[width * channels + channels + i] * offset.fx) * offset.fy) - / (256 * 256); + ((s[i] * (256 - offset.fx) + s[channels + i] * offset.fx) * + (256 - offset.fy) + + (s[width * channels + i] * (256 - offset.fx) + + s[width * channels + channels + i] * offset.fx) * + offset.fy) / + (256 * 256); } } } @@ -148,45 +157,33 @@ void LookupWarpGrid::Apply(const PixelType *input_buffer, } // namespace internal -template<typename PixelType> -void CameraIntrinsics::DistortBuffer(const PixelType *input_buffer, +template <typename PixelType> +void CameraIntrinsics::DistortBuffer(const PixelType* input_buffer, int width, int height, double overscan, int channels, - PixelType *output_buffer) { + PixelType* output_buffer) { assert(channels >= 1); assert(channels <= 4); - distort_.Update<InvertIntrinsicsFunction>(*this, - width, - height, - overscan); - distort_.Apply<PixelType>(input_buffer, - width, - height, - channels, - output_buffer); + distort_.Update<InvertIntrinsicsFunction>(*this, width, height, overscan); + distort_.Apply<PixelType>( + input_buffer, width, height, channels, output_buffer); } -template<typename PixelType> -void CameraIntrinsics::UndistortBuffer(const PixelType *input_buffer, +template <typename PixelType> +void CameraIntrinsics::UndistortBuffer(const PixelType* input_buffer, int width, int height, double overscan, int channels, - PixelType *output_buffer) { + PixelType* output_buffer) { assert(channels >= 1); assert(channels <= 4); - undistort_.Update<ApplyIntrinsicsFunction>(*this, - width, - height, - overscan); - - undistort_.Apply<PixelType>(input_buffer, - width, - height, - channels, - output_buffer); + undistort_.Update<ApplyIntrinsicsFunction>(*this, width, height, overscan); + + undistort_.Apply<PixelType>( + input_buffer, width, height, channels, output_buffer); } } // namespace libmv |