Bundle latest Libmv from upstream

Currently no functional changes, but we might want
to have scoped_array in the future.
This commit is contained in:
Sergey Sharybin 2014-01-28 18:35:46 +06:00
parent 37f1b717eb
commit df471369e2
3 changed files with 73 additions and 23 deletions

@ -1,3 +1,25 @@
commit da4607f010bca0b3532cd4444afbb10bc774fc32
Author: Sergey Sharybin <sergey.vfx@gmail.com>
Date: Tue Jan 28 18:32:39 2014 +0600
Implemented scoped_array and use it in detector
scoped_array is pretty much the same as scoped_ptr
with the only difference that it'll free memory using
delete[] operator.
It also gives some additional API functions to access
array elements.
Currently it only used to manage images denoted as byte
arrays in detector.
Reviewers: keir
Reviewed By: keir
Differential Revision: https://developer.blender.org/D266
commit cd7eb3eff2e69ce5e08570ead83ae6d35ee48857
Author: Sergey Sharybin <sergey.vfx@gmail.com>
Date: Tue Jan 28 17:23:47 2014 +0600
@ -676,13 +698,3 @@ Date: Sat Apr 6 20:49:05 2013 +0600
Discovered when was doing unit-tests for brute region tracker.
This reverts commit daa354c0735b954b0cd7725626e9a3d67416d46b.
commit 5bd89d9b8fb620e7e88bcbfa74165309b872f529
Author: Sergey Sharybin <sergey.vfx@gmail.com>
Date: Sat Apr 6 18:37:37 2013 +0600
Added basic test for brute region tracker
It is failing at this moment and this is caused because
of how SampleLinear works - seems it's assumption about
pixel center is not correct for internal sampling.

@ -21,6 +21,9 @@
#ifndef LIBMV_BASE_SCOPED_PTR_H
#define LIBMV_BASE_SCOPED_PTR_H
#include <cassert>
#include <cstddef>
namespace libmv {
/**
@ -55,6 +58,48 @@ class scoped_ptr {
T *resource_;
};
// Same as scoped_ptr but caller must allocate the data
// with new[] and the destructor will free the memory
// using delete[].
template<typename T>
class scoped_array {
public:
scoped_array(T *array) : array_(array) {}
~scoped_array() { reset(NULL); }
T *get() const { return array_; }
T& operator[](std::ptrdiff_t i) const {
assert(i >= 0);
assert(array_ != NULL);
return array_[i];
}
void reset(T *new_array) {
if (sizeof(T)) {
delete array_;
}
array_ = new_array;
}
T *release() {
T *released_array = array_;
array_ = NULL;
return released_array;
}
private:
T *array_;
// Forbid comparison of different scoped_array types.
template <typename T2> bool operator==(scoped_array<T2> const& p2) const;
template <typename T2> bool operator!=(scoped_array<T2> const& p2) const;
// Disallow evil constructors
scoped_array(const scoped_array&);
void operator=(const scoped_array&);
};
} // namespace libmv
#endif // LIBMV_BASE_SCOPED_PTR_H

@ -99,14 +99,12 @@ void DetectFAST(const FloatImage &grayscale_image,
const int height = grayscale_image.Width() - 2 * margin;
const int stride = grayscale_image.Width();
// TODO(sergey): Use scoped_array to guard de-allocation of the array.
// Same goes to `scores` and `all` arrays here.
unsigned char *byte_image = FloatImageToUCharArray(grayscale_image);
scoped_array<unsigned char> byte_image(FloatImageToUCharArray(grayscale_image));
const int byte_image_offset = margin * stride + margin;
// TODO(MatthiasF): Support targetting a feature count (binary search trackness)
int num_features;
xy *all = fast9_detect(byte_image + byte_image_offset,
xy *all = fast9_detect(byte_image.get() + byte_image_offset,
width,
height,
stride,
@ -114,10 +112,9 @@ void DetectFAST(const FloatImage &grayscale_image,
&num_features);
if (num_features == 0) {
free(all);
delete [] byte_image;
return;
}
int *scores = fast9_score(byte_image + byte_image_offset,
int *scores = fast9_score(byte_image.get() + byte_image_offset,
stride,
all,
num_features,
@ -125,7 +122,6 @@ void DetectFAST(const FloatImage &grayscale_image,
// TODO(MatthiasF): merge with close feature suppression
xy *nonmax = nonmax_suppression(all, scores, num_features, &num_features);
free(all);
delete [] byte_image;
// Remove too close features
// TODO(MatthiasF): A resolution independent parameter would be better than
// distance e.g. a coefficient going from 0 (no minimal distance) to 1
@ -181,13 +177,12 @@ void DetectMORAVEC(const FloatImage &grayscale_image,
const int height = grayscale_image.Width() - 2 * margin;
const int stride = grayscale_image.Width();
// TODO(sergey): Use scoped_array to guard de-allocation of the array.
unsigned char *byte_image = FloatImageToUCharArray(grayscale_image);
scoped_array<unsigned char> byte_image(FloatImageToUCharArray(grayscale_image));
unsigned short histogram[256];
memset(histogram, 0, sizeof(histogram));
ubyte* scores = new ubyte[width*height];
memset(scores, 0, width*height);
scoped_array<ubyte> scores(new ubyte[width*height]);
memset(scores.get(), 0, width*height);
const int r = 1; // radius for self similarity comparison
for (int y = distance; y < height-distance; y++) {
for (int x = distance; x < width-distance; x++) {
@ -240,8 +235,6 @@ void DetectMORAVEC(const FloatImage &grayscale_image,
}
}
}
delete[] scores;
delete[] byte_image;
}
void DetectHarris(const FloatImage &grayscale_image,