Libmv: optimization of PearsonProductMomentCorrelation
Pass the arrays by reference rather than by value, should give some percent of speedup. Also don't pass the dimensions to the function but get them from the images themselves. Hopefully this will give some %% of tracker speedup.
This commit is contained in:
parent
a5e30fc79c
commit
0ff06a9ba5
43
extern/libmv/ChangeLog
vendored
43
extern/libmv/ChangeLog
vendored
@ -1,3 +1,27 @@
|
||||
commit 0ddf3851bfcb8de43660b119a25a77a25674200d
|
||||
Author: Sergey Sharybin <sergey.vfx@gmail.com>
|
||||
Date: Mon Apr 21 14:14:03 2014 +0600
|
||||
|
||||
Optimization of PearsonProductMomentCorrelation
|
||||
|
||||
Pass the arrays by reference rather than by value,
|
||||
should give some percent of speedup.
|
||||
|
||||
Also don't pass the dimensions to the function but
|
||||
get them from the images themselves.
|
||||
|
||||
Hopefully this will give some %% of tracker speedup.
|
||||
|
||||
commit f68fdbe5896a6c5bd8b500caeec61b876c5e44c6
|
||||
Author: Sergey Sharybin <sergey.vfx@gmail.com>
|
||||
Date: Mon Apr 21 14:10:43 2014 +0600
|
||||
|
||||
Fix wrong assert in ResizeImage()
|
||||
|
||||
The assert didn't make any sense because ComputeBoundingBox()
|
||||
is intended to return bounding box in the following way:
|
||||
(xmin, xmax, ymin, ymax).
|
||||
|
||||
commit 1d386b6775a71c499e9b8e4a288c0785c4937677
|
||||
Author: Sergey Sharybin <sergey.vfx@gmail.com>
|
||||
Date: Thu Apr 17 18:42:43 2014 +0600
|
||||
@ -657,22 +681,3 @@ Date: Sat Jun 1 16:20:35 2013 +0600
|
||||
|
||||
Saves couple of time which used to waste on copying objects,
|
||||
also solves win32 compilation errors caused by alignment.
|
||||
|
||||
commit 994c02d0ec55e9ae14a93a3ada6e5d4939247fc3
|
||||
Author: Sergey Sharybin <sergey.vfx@gmail.com>
|
||||
Date: Thu May 30 18:00:03 2013 +0600
|
||||
|
||||
Code cleanup
|
||||
|
||||
- Made some arguments passing to detector const.
|
||||
- Remove unneeded include from track_region header.
|
||||
|
||||
commit 7d0c5325a38e61929f44206761b8aa3565631af5
|
||||
Author: Sergey Sharybin <sergey.vfx@gmail.com>
|
||||
Date: Mon May 13 04:44:14 2013 +0600
|
||||
|
||||
Pass ApplyRadialDistortionCameraIntrinsics input arguments by reference
|
||||
|
||||
This shall save some CPU time on calling copy constructor and give
|
||||
some boost of bundle adjuster (where jet could take some time to
|
||||
be passed by value).
|
||||
|
28
extern/libmv/libmv/image/correlation.h
vendored
28
extern/libmv/libmv/image/correlation.h
vendored
@ -27,34 +27,40 @@
|
||||
namespace libmv {
|
||||
|
||||
inline double PearsonProductMomentCorrelation(
|
||||
Array3Df image_and_gradient1_sampled,
|
||||
Array3Df image_and_gradient2_sampled,
|
||||
int width) {
|
||||
const FloatImage &image_and_gradient1_sampled,
|
||||
const FloatImage &image_and_gradient2_sampled) {
|
||||
assert(image_and_gradient1_sampled.Width() ==
|
||||
image_and_gradient2_sampled.Width());
|
||||
assert(image_and_gradient1_sampled.Height() ==
|
||||
image_and_gradient2_sampled.Height());
|
||||
|
||||
const int width = image_and_gradient1_sampled.Width(),
|
||||
height = image_and_gradient1_sampled.Height();
|
||||
double sX = 0, sY = 0, sXX = 0, sYY = 0, sXY = 0;
|
||||
|
||||
for (int r = 0; r < width; ++r) {
|
||||
for (int r = 0; r < height; ++r) {
|
||||
for (int c = 0; c < width; ++c) {
|
||||
double x = image_and_gradient1_sampled(r, c, 0);
|
||||
double y = image_and_gradient2_sampled(r, c, 0);
|
||||
sX += x;
|
||||
sY += y;
|
||||
sXX += x*x;
|
||||
sYY += y*y;
|
||||
sXY += x*y;
|
||||
sXX += x * x;
|
||||
sYY += y * y;
|
||||
sXY += x * y;
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize.
|
||||
double N = width * width;
|
||||
double N = width * height;
|
||||
sX /= N;
|
||||
sY /= N;
|
||||
sXX /= N;
|
||||
sYY /= N;
|
||||
sXY /= N;
|
||||
|
||||
double var_x = sXX - sX*sX;
|
||||
double var_y = sYY - sY*sY;
|
||||
double covariance_xy = sXY - sX*sY;
|
||||
double var_x = sXX - sX * sX;
|
||||
double var_y = sYY - sY * sY;
|
||||
double covariance_xy = sXY - sX * sY;
|
||||
|
||||
double correlation = covariance_xy / sqrt(var_x * var_y);
|
||||
LG << "Covariance xy: " << covariance_xy
|
||||
|
@ -364,8 +364,7 @@ bool BruteRegionTracker::Track(const FloatImage &image1,
|
||||
// for sanity.
|
||||
double correlation = PearsonProductMomentCorrelation(
|
||||
image_and_gradient1_sampled,
|
||||
image_and_gradient2_sampled,
|
||||
pattern_width);
|
||||
image_and_gradient2_sampled);
|
||||
|
||||
LG << "Final correlation: " << correlation;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user