Warning fixes continued
This commit is contained in:
@@ -67,15 +67,15 @@ LevMarqSparse::LevMarqSparse(int npoints, // number of points
|
||||
// 1 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, // starting vector of parameters, first cameras then points
|
||||
Mat& X_, // measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria criteria, // termination criteria
|
||||
TermCriteria _criteria, // termination criteria
|
||||
|
||||
// callback for estimation of Jacobian matrices
|
||||
void (CV_CDECL * fjac)(int i, int j, Mat& point_params,
|
||||
void (CV_CDECL * _fjac)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
// callback for estimation of backprojection errors
|
||||
void (CV_CDECL * func)(int i, int j, Mat& point_params,
|
||||
void (CV_CDECL * _func)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& estim, void* data),
|
||||
void* data, // user-specific data passed to the callbacks
|
||||
void* _data, // user-specific data passed to the callbacks
|
||||
BundleAdjustCallback _cb, void* _user_data
|
||||
) {
|
||||
Vis_index = X = prevP = P = deltaP = err = JtJ_diag = S = hX = NULL;
|
||||
@@ -86,7 +86,7 @@ LevMarqSparse::LevMarqSparse(int npoints, // number of points
|
||||
user_data = _user_data;
|
||||
|
||||
run(npoints, ncameras, nPointParams, nCameraParams, nErrParams, visibility,
|
||||
P0, X_, criteria, fjac, func, data);
|
||||
P0, X_, _criteria, _fjac, _func, _data);
|
||||
}
|
||||
|
||||
void LevMarqSparse::clear() {
|
||||
@@ -443,9 +443,11 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
} //U_j and ea_j computed for all j
|
||||
|
||||
// if (!(iters%100))
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = prevErrNorm*prevErrNorm, e2n = e2 / nviz;
|
||||
std::cerr<<"Iteration: "<<iters<<", normError: "<<e2<<" ("<<e2n<<")"<<std::endl;
|
||||
{
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = prevErrNorm*prevErrNorm, e2n = e2 / nviz;
|
||||
std::cerr<<"Iteration: "<<iters<<", normError: "<<e2<<" ("<<e2n<<")"<<std::endl;
|
||||
}
|
||||
if (cb)
|
||||
cb(iters, prevErrNorm, user_data);
|
||||
//compute V_i and eb_i
|
||||
@@ -676,10 +678,12 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
errNorm > prevErrNorm ) { //step was not accepted
|
||||
//increase lambda and reject change
|
||||
lambda *= 10;
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = errNorm*errNorm, e2_prev = prevErrNorm*prevErrNorm;
|
||||
double e2n = e2/nviz, e2n_prev = e2_prev/nviz;
|
||||
std::cerr<<"move failed: lambda = "<<lambda<<", e2 = "<<e2<<" ("<<e2n<<") > "<<e2_prev<<" ("<<e2n_prev<<")"<<std::endl;
|
||||
{
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = errNorm*errNorm, e2_prev = prevErrNorm*prevErrNorm;
|
||||
double e2n = e2/nviz, e2n_prev = e2_prev/nviz;
|
||||
std::cerr<<"move failed: lambda = "<<lambda<<", e2 = "<<e2<<" ("<<e2n<<") > "<<e2_prev<<" ("<<e2n_prev<<")"<<std::endl;
|
||||
}
|
||||
|
||||
//restore diagonal from backup
|
||||
{
|
||||
@@ -886,9 +890,9 @@ static void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, C
|
||||
double c[4] = { g+2*p1*y_strike+4*p2*x_strike, 2*p1*x_strike,
|
||||
2*p2*y_strike, g+2*p2*x_strike + 4*p1*y_strike };
|
||||
|
||||
CvMat coeffmat = cvMat(2,2,CV_64F, c );
|
||||
CvMat coeffmat2 = cvMat(2,2,CV_64F, c );
|
||||
|
||||
cvMatMul(&coeffmat, dstrike_dbig, dstrike2_dbig );
|
||||
cvMatMul(&coeffmat2, dstrike_dbig, dstrike2_dbig );
|
||||
|
||||
cvGEMM( &strike, dg_dbig, 1, NULL, 0, tmp, CV_GEMM_A_T );
|
||||
cvAdd( dstrike2_dbig, tmp, dstrike2_dbig );
|
||||
|
@@ -180,13 +180,13 @@ void BasicRetinaFilter::setLPfilterParameters(const float beta, const float tau,
|
||||
}
|
||||
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float _a = _filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[1+tableOffset]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
|
||||
float a = _filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[1+tableOffset]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[2+tableOffset] =tau;
|
||||
|
||||
//std::cout<<"BasicRetinaFilter::normal:"<<(1.0-_a)*(1.0-_a)*(1.0-_a)*(1.0-_a)/(1.0+_beta)<<" -> old:"<<(1-_a)*(1-_a)*(1-_a)*(1-_a)/(1+_beta)<<std::endl;
|
||||
//std::cout<<"BasicRetinaFilter::normal:"<<(1.0-a)*(1.0-a)*(1.0-a)*(1.0-a)/(1.0+_beta)<<" -> old:"<<(1-a)*(1-a)*(1-a)*(1-a)/(1+_beta)<<std::endl;
|
||||
|
||||
//std::cout<<"BasicRetinaFilter::_a="<<_a<<", gain="<<_filteringCoeficientsTable[1+tableOffset]<<", tau="<<tau<<std::endl;
|
||||
//std::cout<<"BasicRetinaFilter::a="<<a<<", gain="<<_filteringCoeficientsTable[1+tableOffset]<<", tau="<<tau<<std::endl;
|
||||
}
|
||||
|
||||
void BasicRetinaFilter::setProgressiveFilterConstants_CentredAccuracy(const float beta, const float tau, const float alpha0, const unsigned int filterIndex)
|
||||
@@ -210,8 +210,8 @@ void BasicRetinaFilter::setProgressiveFilterConstants_CentredAccuracy(const floa
|
||||
|
||||
float _alpha=0.8f;
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float _a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
|
||||
float a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[tableOffset+2] =tau;
|
||||
|
||||
float commonFactor=alpha0/(float)sqrt(_halfNBcolumns*_halfNBcolumns+_halfNBrows*_halfNBrows+1.0f);
|
||||
@@ -266,8 +266,8 @@ void BasicRetinaFilter::setProgressiveFilterConstants_CustomAccuracy(const float
|
||||
}
|
||||
unsigned int tableOffset=filterIndex*3;
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float _a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
|
||||
float a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[tableOffset+2] =tau;
|
||||
|
||||
//memset(_progressiveSpatialConstant, 255, _filterOutput.getNBpixels());
|
||||
|
@@ -68,10 +68,10 @@ void CvMeanShiftTracker::newTrackingWindow(Mat image, Rect selection)
|
||||
mixChannels(&hsv, 1, &hue, 1, channels, 2);
|
||||
|
||||
Mat roi(hue, selection);
|
||||
Mat maskroi(mask, selection);
|
||||
Mat mskroi(mask, selection);
|
||||
int ch[] = {0, 1};
|
||||
int chsize[] = {32, 32};
|
||||
calcHist(&roi, 1, ch, maskroi, hist, 1, chsize, ranges);
|
||||
calcHist(&roi, 1, ch, mskroi, hist, 1, chsize, ranges);
|
||||
normalize(hist, hist, 0, 255, CV_MINMAX);
|
||||
|
||||
prev_trackwindow = selection;
|
||||
|
@@ -22,7 +22,7 @@ namespace cv
|
||||
{
|
||||
|
||||
using std::set;
|
||||
|
||||
|
||||
// Reads a sequence from a FileNode::SEQ with type _Tp into a result vector.
|
||||
template<typename _Tp>
|
||||
inline void readFileNodeList(const FileNode& fn, vector<_Tp>& result) {
|
||||
@@ -48,7 +48,7 @@ inline void writeFileNodeList(FileStorage& fs, const string& name,
|
||||
}
|
||||
fs << "]";
|
||||
}
|
||||
|
||||
|
||||
static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double beta=0)
|
||||
{
|
||||
// number of samples
|
||||
@@ -67,7 +67,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
// Removes duplicate elements in a given vector.
|
||||
template<typename _Tp>
|
||||
inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
||||
@@ -82,7 +82,7 @@ inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Turk, M., and Pentland, A. "Eigenfaces for recognition.". Journal of
|
||||
// Cognitive Neuroscience 3 (1991), 71–86.
|
||||
class Eigenfaces : public FaceRecognizer
|
||||
@@ -124,10 +124,10 @@ public:
|
||||
|
||||
// See FaceRecognizer::save.
|
||||
void save(FileStorage& fs) const;
|
||||
|
||||
|
||||
AlgorithmInfo* info() const;
|
||||
};
|
||||
|
||||
|
||||
// Belhumeur, P. N., Hespanha, J., and Kriegman, D. "Eigenfaces vs. Fisher-
|
||||
// faces: Recognition using class specific linear projection.". IEEE
|
||||
// Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997),
|
||||
@@ -208,11 +208,11 @@ public:
|
||||
//
|
||||
// radius, neighbors are used in the local binary patterns creation.
|
||||
// grid_x, grid_y control the grid size of the spatial histograms.
|
||||
LBPH(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8) :
|
||||
_grid_x(grid_x),
|
||||
_grid_y(grid_y),
|
||||
_radius(radius),
|
||||
_neighbors(neighbors) {}
|
||||
LBPH(int radius_=1, int neighbors_=8, int grid_x_=8, int grid_y_=8) :
|
||||
_grid_x(grid_x_),
|
||||
_grid_y(grid_y_),
|
||||
_radius(radius_),
|
||||
_neighbors(neighbors_) {}
|
||||
|
||||
// Initializes and computes this LBPH Model. The current implementation is
|
||||
// rather fixed as it uses the Extended Local Binary Patterns per default.
|
||||
@@ -221,12 +221,12 @@ public:
|
||||
// (grid_x=8), (grid_y=8) controls the grid size of the spatial histograms.
|
||||
LBPH(InputArray src,
|
||||
InputArray labels,
|
||||
int radius=1, int neighbors=8,
|
||||
int grid_x=8, int grid_y=8) :
|
||||
_grid_x(grid_x),
|
||||
_grid_y(grid_y),
|
||||
_radius(radius),
|
||||
_neighbors(neighbors) {
|
||||
int radius_=1, int neighbors_=8,
|
||||
int grid_x_=8, int grid_y_=8) :
|
||||
_grid_x(grid_x_),
|
||||
_grid_y(grid_y_),
|
||||
_radius(radius_),
|
||||
_neighbors(neighbors_) {
|
||||
train(src, labels);
|
||||
}
|
||||
|
||||
@@ -359,9 +359,9 @@ void Fisherfaces::train(InputArray src, InputArray _lbls) {
|
||||
// get data
|
||||
Mat labels = _lbls.getMat();
|
||||
Mat data = asRowMatrix(src, CV_64FC1);
|
||||
|
||||
|
||||
CV_Assert( labels.type() == CV_32S && (labels.cols == 1 || labels.rows == 1));
|
||||
|
||||
|
||||
// dimensionality
|
||||
int N = data.rows; // number of samples
|
||||
//int D = data.cols; // dimension of samples
|
||||
@@ -369,7 +369,7 @@ void Fisherfaces::train(InputArray src, InputArray _lbls) {
|
||||
if(labels.total() != (size_t)N)
|
||||
CV_Error(CV_StsUnsupportedFormat, "Labels must be given as integer (CV_32SC1).");
|
||||
// compute the Fisherfaces
|
||||
|
||||
|
||||
vector<int> ll;
|
||||
labels.copyTo(ll);
|
||||
int C = (int)remove_dups(ll).size(); // number of unique classes
|
||||
@@ -570,7 +570,7 @@ static Mat histc(InputArray _src, int minVal, int maxVal, bool normed)
|
||||
return Mat();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static Mat spatial_histogram(InputArray _src, int numPatterns,
|
||||
int grid_x, int grid_y, bool normed)
|
||||
{
|
||||
@@ -610,7 +610,7 @@ static Mat elbp(InputArray src, int radius, int neighbors) {
|
||||
elbp(src, dst, radius, neighbors);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
void LBPH::load(const FileStorage& fs) {
|
||||
fs["radius"] >> _radius;
|
||||
fs["neighbors"] >> _neighbors;
|
||||
@@ -684,24 +684,24 @@ int LBPH::predict(InputArray _src) const {
|
||||
}
|
||||
return minClass;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Ptr<FaceRecognizer> createEigenFaceRecognizer(int num_components)
|
||||
{
|
||||
return new Eigenfaces(num_components);
|
||||
}
|
||||
|
||||
|
||||
Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components)
|
||||
{
|
||||
return new Fisherfaces(num_components);
|
||||
}
|
||||
|
||||
|
||||
Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius, int neighbors,
|
||||
int grid_x, int grid_y)
|
||||
{
|
||||
return new LBPH(radius, neighbors, grid_x, grid_y);
|
||||
}
|
||||
|
||||
|
||||
CV_INIT_ALGORITHM(Eigenfaces, "FaceRecognizer.Eigenfaces",
|
||||
obj.info()->addParam(obj, "ncomponents", obj._num_components);
|
||||
obj.info()->addParam(obj, "projections", obj._projections, true);
|
||||
@@ -716,8 +716,8 @@ CV_INIT_ALGORITHM(Fisherfaces, "FaceRecognizer.Fisherfaces",
|
||||
obj.info()->addParam(obj, "labels", obj._labels, true);
|
||||
obj.info()->addParam(obj, "eigenvectors", obj._eigenvectors, true);
|
||||
obj.info()->addParam(obj, "eigenvalues", obj._eigenvalues, true);
|
||||
obj.info()->addParam(obj, "mean", obj._mean, true));
|
||||
|
||||
obj.info()->addParam(obj, "mean", obj._mean, true));
|
||||
|
||||
CV_INIT_ALGORITHM(LBPH, "FaceRecognizer.LBPH",
|
||||
obj.info()->addParam(obj, "radius", obj._radius);
|
||||
obj.info()->addParam(obj, "neighbors", obj._neighbors);
|
||||
@@ -725,7 +725,7 @@ CV_INIT_ALGORITHM(LBPH, "FaceRecognizer.LBPH",
|
||||
obj.info()->addParam(obj, "grid_y", obj._grid_y);
|
||||
obj.info()->addParam(obj, "histograms", obj._histograms, true);
|
||||
obj.info()->addParam(obj, "labels", obj._labels, true));
|
||||
|
||||
|
||||
bool initModule_contrib()
|
||||
{
|
||||
Ptr<Algorithm> efaces = createEigenfaces(), ffaces = createFisherfaces(), lbph = createLBPH();
|
||||
|
@@ -235,19 +235,19 @@ private:
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp **alloc_2d(int m, int n) {
|
||||
_Tp **alloc_2d(int m, int _n) {
|
||||
_Tp **arr = new _Tp*[m];
|
||||
for (int i = 0; i < m; i++)
|
||||
arr[i] = new _Tp[n];
|
||||
arr[i] = new _Tp[_n];
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp **alloc_2d(int m, int n, _Tp val) {
|
||||
_Tp **arr = alloc_2d<_Tp> (m, n);
|
||||
_Tp **alloc_2d(int m, int _n, _Tp val) {
|
||||
_Tp **arr = alloc_2d<_Tp> (m, _n);
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int j = 0; j < _n; j++) {
|
||||
arr[i][j] = val;
|
||||
}
|
||||
}
|
||||
@@ -255,17 +255,17 @@ private:
|
||||
}
|
||||
|
||||
void cdiv(double xr, double xi, double yr, double yi) {
|
||||
double r, d;
|
||||
double r, dv;
|
||||
if (std::abs(yr) > std::abs(yi)) {
|
||||
r = yi / yr;
|
||||
d = yr + r * yi;
|
||||
cdivr = (xr + r * xi) / d;
|
||||
cdivi = (xi - r * xr) / d;
|
||||
dv = yr + r * yi;
|
||||
cdivr = (xr + r * xi) / dv;
|
||||
cdivi = (xi - r * xr) / dv;
|
||||
} else {
|
||||
r = yr / yi;
|
||||
d = yi + r * yr;
|
||||
cdivr = (r * xr + xi) / d;
|
||||
cdivi = (r * xi - xr) / d;
|
||||
dv = yi + r * yr;
|
||||
cdivr = (r * xr + xi) / dv;
|
||||
cdivi = (r * xi - xr) / dv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ private:
|
||||
|
||||
// Initialize
|
||||
int nn = this->n;
|
||||
int n = nn - 1;
|
||||
int n1 = nn - 1;
|
||||
int low = 0;
|
||||
int high = nn - 1;
|
||||
double eps = pow(2.0, -52.0);
|
||||
@@ -302,10 +302,10 @@ private:
|
||||
|
||||
// Outer loop over eigenvalue index
|
||||
int iter = 0;
|
||||
while (n >= low) {
|
||||
while (n1 >= low) {
|
||||
|
||||
// Look for single small sub-diagonal element
|
||||
int l = n;
|
||||
int l = n1;
|
||||
while (l > low) {
|
||||
s = std::abs(H[l - 1][l - 1]) + std::abs(H[l][l]);
|
||||
if (s == 0.0) {
|
||||
@@ -320,23 +320,23 @@ private:
|
||||
// Check for convergence
|
||||
// One root found
|
||||
|
||||
if (l == n) {
|
||||
H[n][n] = H[n][n] + exshift;
|
||||
d[n] = H[n][n];
|
||||
e[n] = 0.0;
|
||||
n--;
|
||||
if (l == n1) {
|
||||
H[n1][n1] = H[n1][n1] + exshift;
|
||||
d[n1] = H[n1][n1];
|
||||
e[n1] = 0.0;
|
||||
n1--;
|
||||
iter = 0;
|
||||
|
||||
// Two roots found
|
||||
|
||||
} else if (l == n - 1) {
|
||||
w = H[n][n - 1] * H[n - 1][n];
|
||||
p = (H[n - 1][n - 1] - H[n][n]) / 2.0;
|
||||
} else if (l == n1 - 1) {
|
||||
w = H[n1][n1 - 1] * H[n1 - 1][n1];
|
||||
p = (H[n1 - 1][n1 - 1] - H[n1][n1]) / 2.0;
|
||||
q = p * p + w;
|
||||
z = sqrt(std::abs(q));
|
||||
H[n][n] = H[n][n] + exshift;
|
||||
H[n - 1][n - 1] = H[n - 1][n - 1] + exshift;
|
||||
x = H[n][n];
|
||||
H[n1][n1] = H[n1][n1] + exshift;
|
||||
H[n1 - 1][n1 - 1] = H[n1 - 1][n1 - 1] + exshift;
|
||||
x = H[n1][n1];
|
||||
|
||||
// Real pair
|
||||
|
||||
@@ -346,14 +346,14 @@ private:
|
||||
} else {
|
||||
z = p - z;
|
||||
}
|
||||
d[n - 1] = x + z;
|
||||
d[n] = d[n - 1];
|
||||
d[n1 - 1] = x + z;
|
||||
d[n1] = d[n1 - 1];
|
||||
if (z != 0.0) {
|
||||
d[n] = x - w / z;
|
||||
d[n1] = x - w / z;
|
||||
}
|
||||
e[n - 1] = 0.0;
|
||||
e[n] = 0.0;
|
||||
x = H[n][n - 1];
|
||||
e[n1 - 1] = 0.0;
|
||||
e[n1] = 0.0;
|
||||
x = H[n1][n1 - 1];
|
||||
s = std::abs(x) + std::abs(z);
|
||||
p = x / s;
|
||||
q = z / s;
|
||||
@@ -363,37 +363,37 @@ private:
|
||||
|
||||
// Row modification
|
||||
|
||||
for (int j = n - 1; j < nn; j++) {
|
||||
z = H[n - 1][j];
|
||||
H[n - 1][j] = q * z + p * H[n][j];
|
||||
H[n][j] = q * H[n][j] - p * z;
|
||||
for (int j = n1 - 1; j < nn; j++) {
|
||||
z = H[n1 - 1][j];
|
||||
H[n1 - 1][j] = q * z + p * H[n1][j];
|
||||
H[n1][j] = q * H[n1][j] - p * z;
|
||||
}
|
||||
|
||||
// Column modification
|
||||
|
||||
for (int i = 0; i <= n; i++) {
|
||||
z = H[i][n - 1];
|
||||
H[i][n - 1] = q * z + p * H[i][n];
|
||||
H[i][n] = q * H[i][n] - p * z;
|
||||
for (int i = 0; i <= n1; i++) {
|
||||
z = H[i][n1 - 1];
|
||||
H[i][n1 - 1] = q * z + p * H[i][n1];
|
||||
H[i][n1] = q * H[i][n1] - p * z;
|
||||
}
|
||||
|
||||
// Accumulate transformations
|
||||
|
||||
for (int i = low; i <= high; i++) {
|
||||
z = V[i][n - 1];
|
||||
V[i][n - 1] = q * z + p * V[i][n];
|
||||
V[i][n] = q * V[i][n] - p * z;
|
||||
z = V[i][n1 - 1];
|
||||
V[i][n1 - 1] = q * z + p * V[i][n1];
|
||||
V[i][n1] = q * V[i][n1] - p * z;
|
||||
}
|
||||
|
||||
// Complex pair
|
||||
|
||||
} else {
|
||||
d[n - 1] = x + p;
|
||||
d[n] = x + p;
|
||||
e[n - 1] = z;
|
||||
e[n] = -z;
|
||||
d[n1 - 1] = x + p;
|
||||
d[n1] = x + p;
|
||||
e[n1 - 1] = z;
|
||||
e[n1] = -z;
|
||||
}
|
||||
n = n - 2;
|
||||
n1 = n1 - 2;
|
||||
iter = 0;
|
||||
|
||||
// No convergence yet
|
||||
@@ -402,22 +402,22 @@ private:
|
||||
|
||||
// Form shift
|
||||
|
||||
x = H[n][n];
|
||||
x = H[n1][n1];
|
||||
y = 0.0;
|
||||
w = 0.0;
|
||||
if (l < n) {
|
||||
y = H[n - 1][n - 1];
|
||||
w = H[n][n - 1] * H[n - 1][n];
|
||||
if (l < n1) {
|
||||
y = H[n1 - 1][n1 - 1];
|
||||
w = H[n1][n1 - 1] * H[n1 - 1][n1];
|
||||
}
|
||||
|
||||
// Wilkinson's original ad hoc shift
|
||||
|
||||
if (iter == 10) {
|
||||
exshift += x;
|
||||
for (int i = low; i <= n; i++) {
|
||||
for (int i = low; i <= n1; i++) {
|
||||
H[i][i] -= x;
|
||||
}
|
||||
s = std::abs(H[n][n - 1]) + std::abs(H[n - 1][n - 2]);
|
||||
s = std::abs(H[n1][n1 - 1]) + std::abs(H[n1 - 1][n1 - 2]);
|
||||
x = y = 0.75 * s;
|
||||
w = -0.4375 * s * s;
|
||||
}
|
||||
@@ -433,7 +433,7 @@ private:
|
||||
s = -s;
|
||||
}
|
||||
s = x - w / ((y - x) / 2.0 + s);
|
||||
for (int i = low; i <= n; i++) {
|
||||
for (int i = low; i <= n1; i++) {
|
||||
H[i][i] -= s;
|
||||
}
|
||||
exshift += s;
|
||||
@@ -444,7 +444,7 @@ private:
|
||||
iter = iter + 1; // (Could check iteration count here.)
|
||||
|
||||
// Look for two consecutive small sub-diagonal elements
|
||||
int m = n - 2;
|
||||
int m = n1 - 2;
|
||||
while (m >= l) {
|
||||
z = H[m][m];
|
||||
r = x - z;
|
||||
@@ -467,7 +467,7 @@ private:
|
||||
m--;
|
||||
}
|
||||
|
||||
for (int i = m + 2; i <= n; i++) {
|
||||
for (int i = m + 2; i <= n1; i++) {
|
||||
H[i][i - 2] = 0.0;
|
||||
if (i > m + 2) {
|
||||
H[i][i - 3] = 0.0;
|
||||
@@ -476,8 +476,8 @@ private:
|
||||
|
||||
// Double QR step involving rows l:n and columns m:n
|
||||
|
||||
for (int k = m; k <= n - 1; k++) {
|
||||
bool notlast = (k != n - 1);
|
||||
for (int k = m; k <= n1 - 1; k++) {
|
||||
bool notlast = (k != n1 - 1);
|
||||
if (k != m) {
|
||||
p = H[k][k - 1];
|
||||
q = H[k + 1][k - 1];
|
||||
@@ -523,7 +523,7 @@ private:
|
||||
|
||||
// Column modification
|
||||
|
||||
for (int i = 0; i <= min(n, k + 3); i++) {
|
||||
for (int i = 0; i <= min(n1, k + 3); i++) {
|
||||
p = x * H[i][k] + y * H[i][k + 1];
|
||||
if (notlast) {
|
||||
p = p + z * H[i][k + 2];
|
||||
@@ -547,7 +547,7 @@ private:
|
||||
} // (s != 0)
|
||||
} // k loop
|
||||
} // check convergence
|
||||
} // while (n >= low)
|
||||
} // while (n1 >= low)
|
||||
|
||||
// Backsubstitute to find vectors of upper triangular form
|
||||
|
||||
@@ -555,20 +555,20 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
for (n = nn - 1; n >= 0; n--) {
|
||||
p = d[n];
|
||||
q = e[n];
|
||||
for (n1 = nn - 1; n1 >= 0; n1--) {
|
||||
p = d[n1];
|
||||
q = e[n1];
|
||||
|
||||
// Real vector
|
||||
|
||||
if (q == 0) {
|
||||
int l = n;
|
||||
H[n][n] = 1.0;
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
int l = n1;
|
||||
H[n1][n1] = 1.0;
|
||||
for (int i = n1 - 1; i >= 0; i--) {
|
||||
w = H[i][i] - p;
|
||||
r = 0.0;
|
||||
for (int j = l; j <= n; j++) {
|
||||
r = r + H[i][j] * H[j][n];
|
||||
for (int j = l; j <= n1; j++) {
|
||||
r = r + H[i][j] * H[j][n1];
|
||||
}
|
||||
if (e[i] < 0.0) {
|
||||
z = w;
|
||||
@@ -577,9 +577,9 @@ private:
|
||||
l = i;
|
||||
if (e[i] == 0.0) {
|
||||
if (w != 0.0) {
|
||||
H[i][n] = -r / w;
|
||||
H[i][n1] = -r / w;
|
||||
} else {
|
||||
H[i][n] = -r / (eps * norm);
|
||||
H[i][n1] = -r / (eps * norm);
|
||||
}
|
||||
|
||||
// Solve real equations
|
||||
@@ -589,20 +589,20 @@ private:
|
||||
y = H[i + 1][i];
|
||||
q = (d[i] - p) * (d[i] - p) + e[i] * e[i];
|
||||
t = (x * s - z * r) / q;
|
||||
H[i][n] = t;
|
||||
H[i][n1] = t;
|
||||
if (std::abs(x) > std::abs(z)) {
|
||||
H[i + 1][n] = (-r - w * t) / x;
|
||||
H[i + 1][n1] = (-r - w * t) / x;
|
||||
} else {
|
||||
H[i + 1][n] = (-s - y * t) / z;
|
||||
H[i + 1][n1] = (-s - y * t) / z;
|
||||
}
|
||||
}
|
||||
|
||||
// Overflow control
|
||||
|
||||
t = std::abs(H[i][n]);
|
||||
t = std::abs(H[i][n1]);
|
||||
if ((eps * t) * t > 1) {
|
||||
for (int j = i; j <= n; j++) {
|
||||
H[j][n] = H[j][n] / t;
|
||||
for (int j = i; j <= n1; j++) {
|
||||
H[j][n1] = H[j][n1] / t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -611,27 +611,27 @@ private:
|
||||
// Complex vector
|
||||
|
||||
} else if (q < 0) {
|
||||
int l = n - 1;
|
||||
int l = n1 - 1;
|
||||
|
||||
// Last vector component imaginary so matrix is triangular
|
||||
|
||||
if (std::abs(H[n][n - 1]) > std::abs(H[n - 1][n])) {
|
||||
H[n - 1][n - 1] = q / H[n][n - 1];
|
||||
H[n - 1][n] = -(H[n][n] - p) / H[n][n - 1];
|
||||
if (std::abs(H[n1][n1 - 1]) > std::abs(H[n1 - 1][n1])) {
|
||||
H[n1 - 1][n1 - 1] = q / H[n1][n1 - 1];
|
||||
H[n1 - 1][n1] = -(H[n1][n1] - p) / H[n1][n1 - 1];
|
||||
} else {
|
||||
cdiv(0.0, -H[n - 1][n], H[n - 1][n - 1] - p, q);
|
||||
H[n - 1][n - 1] = cdivr;
|
||||
H[n - 1][n] = cdivi;
|
||||
cdiv(0.0, -H[n1 - 1][n1], H[n1 - 1][n1 - 1] - p, q);
|
||||
H[n1 - 1][n1 - 1] = cdivr;
|
||||
H[n1 - 1][n1] = cdivi;
|
||||
}
|
||||
H[n][n - 1] = 0.0;
|
||||
H[n][n] = 1.0;
|
||||
for (int i = n - 2; i >= 0; i--) {
|
||||
H[n1][n1 - 1] = 0.0;
|
||||
H[n1][n1] = 1.0;
|
||||
for (int i = n1 - 2; i >= 0; i--) {
|
||||
double ra, sa, vr, vi;
|
||||
ra = 0.0;
|
||||
sa = 0.0;
|
||||
for (int j = l; j <= n; j++) {
|
||||
ra = ra + H[i][j] * H[j][n - 1];
|
||||
sa = sa + H[i][j] * H[j][n];
|
||||
for (int j = l; j <= n1; j++) {
|
||||
ra = ra + H[i][j] * H[j][n1 - 1];
|
||||
sa = sa + H[i][j] * H[j][n1];
|
||||
}
|
||||
w = H[i][i] - p;
|
||||
|
||||
@@ -643,8 +643,8 @@ private:
|
||||
l = i;
|
||||
if (e[i] == 0) {
|
||||
cdiv(-ra, -sa, w, q);
|
||||
H[i][n - 1] = cdivr;
|
||||
H[i][n] = cdivi;
|
||||
H[i][n1 - 1] = cdivr;
|
||||
H[i][n1] = cdivi;
|
||||
} else {
|
||||
|
||||
// Solve complex equations
|
||||
@@ -659,28 +659,28 @@ private:
|
||||
}
|
||||
cdiv(x * r - z * ra + q * sa,
|
||||
x * s - z * sa - q * ra, vr, vi);
|
||||
H[i][n - 1] = cdivr;
|
||||
H[i][n] = cdivi;
|
||||
H[i][n1 - 1] = cdivr;
|
||||
H[i][n1] = cdivi;
|
||||
if (std::abs(x) > (std::abs(z) + std::abs(q))) {
|
||||
H[i + 1][n - 1] = (-ra - w * H[i][n - 1] + q
|
||||
* H[i][n]) / x;
|
||||
H[i + 1][n] = (-sa - w * H[i][n] - q * H[i][n
|
||||
H[i + 1][n1 - 1] = (-ra - w * H[i][n1 - 1] + q
|
||||
* H[i][n1]) / x;
|
||||
H[i + 1][n1] = (-sa - w * H[i][n1] - q * H[i][n1
|
||||
- 1]) / x;
|
||||
} else {
|
||||
cdiv(-r - y * H[i][n - 1], -s - y * H[i][n], z,
|
||||
cdiv(-r - y * H[i][n1 - 1], -s - y * H[i][n1], z,
|
||||
q);
|
||||
H[i + 1][n - 1] = cdivr;
|
||||
H[i + 1][n] = cdivi;
|
||||
H[i + 1][n1 - 1] = cdivr;
|
||||
H[i + 1][n1] = cdivi;
|
||||
}
|
||||
}
|
||||
|
||||
// Overflow control
|
||||
|
||||
t = max(std::abs(H[i][n - 1]), std::abs(H[i][n]));
|
||||
t = max(std::abs(H[i][n1 - 1]), std::abs(H[i][n1]));
|
||||
if ((eps * t) * t > 1) {
|
||||
for (int j = i; j <= n; j++) {
|
||||
H[j][n - 1] = H[j][n - 1] / t;
|
||||
H[j][n] = H[j][n] / t;
|
||||
for (int j = i; j <= n1; j++) {
|
||||
H[j][n1 - 1] = H[j][n1 - 1] / t;
|
||||
H[j][n1] = H[j][n1] / t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -60,9 +60,9 @@ ICVS 2011, Sophia Antipolis, France, September 20-22, 2011
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
||||
//------------------------------------interp-------------------------------------------
|
||||
LogPolar_Interp::LogPolar_Interp(int w, int h, Point2i center, int R, double ro0, int interp, int full, int S, int sp)
|
||||
LogPolar_Interp::LogPolar_Interp(int w, int h, Point2i center, int _R, double _ro0, int _interp, int full, int _S, int sp)
|
||||
{
|
||||
if ( (center.x!=w/2 || center.y!=h/2) && full==0) full=1;
|
||||
|
||||
@@ -97,23 +97,23 @@ LogPolar_Interp::LogPolar_Interp(int w, int h, Point2i center, int R, double ro0
|
||||
|
||||
if (sp){
|
||||
int jc=M/2-1, ic=N/2-1;
|
||||
int romax=min(ic, jc);
|
||||
double a=exp(log((double)(romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(a-1)+0.5);
|
||||
int _romax=min(ic, jc);
|
||||
double _a=exp(log((double)(_romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(_a-1)+0.5);
|
||||
}
|
||||
|
||||
this->interp=interp;
|
||||
interp=_interp;
|
||||
|
||||
create_map(M, N, R, S, ro0);
|
||||
create_map(M, N, _R, _S, _ro0);
|
||||
}
|
||||
|
||||
void LogPolar_Interp::create_map(int M, int N, int R, int S, double ro0)
|
||||
void LogPolar_Interp::create_map(int _M, int _N, int _R, int _S, double _ro0)
|
||||
{
|
||||
this->M=M;
|
||||
this->N=N;
|
||||
this->R=R;
|
||||
this->S=S;
|
||||
this->ro0=ro0;
|
||||
M=_M;
|
||||
N=_N;
|
||||
R=_R;
|
||||
S=_S;
|
||||
ro0=_ro0;
|
||||
|
||||
int jc=N/2-1, ic=M/2-1;
|
||||
romax=min(ic, jc);
|
||||
@@ -130,7 +130,7 @@ void LogPolar_Interp::create_map(int M, int N, int R, int S, double ro0)
|
||||
for(int u=0; u<R; u++)
|
||||
{
|
||||
Rsri.at<float>(v,u)=(float)(ro0*pow(a,u)*sin(v/q)+jc);
|
||||
Csri.at<float>(v,u)=(float)(ro0*pow(a,u)*cos(v/q)+ic);
|
||||
Csri.at<float>(v,u)=(float)(ro0*pow(a,u)*cos(v/q)+ic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ void LogPolar_Interp::create_map(int M, int N, int R, int S, double ro0)
|
||||
const Mat LogPolar_Interp::to_cortical(const Mat &source)
|
||||
{
|
||||
Mat out(S,R,CV_8UC1,Scalar(0));
|
||||
|
||||
|
||||
Mat source_border;
|
||||
copyMakeBorder(source,source_border,top,bottom,left,right,BORDER_CONSTANT,Scalar(0));
|
||||
|
||||
@@ -173,7 +173,7 @@ const Mat LogPolar_Interp::to_cartesian(const Mat &source)
|
||||
Mat out(N,M,CV_8UC1,Scalar(0));
|
||||
|
||||
Mat source_border;
|
||||
|
||||
|
||||
if (interp==INTER_NEAREST || interp==INTER_LINEAR){
|
||||
copyMakeBorder(source,source_border,0,1,0,0,BORDER_CONSTANT,Scalar(0));
|
||||
Mat rowS0 = source_border.row(S);
|
||||
@@ -208,7 +208,7 @@ LogPolar_Interp::~LogPolar_Interp()
|
||||
|
||||
//------------------------------------overlapping----------------------------------
|
||||
|
||||
LogPolar_Overlapping::LogPolar_Overlapping(int w, int h, Point2i center, int R, double ro0, int full, int S, int sp)
|
||||
LogPolar_Overlapping::LogPolar_Overlapping(int w, int h, Point2i center, int _R, double _ro0, int full, int _S, int sp)
|
||||
{
|
||||
if ( (center.x!=w/2 || center.y!=h/2) && full==0) full=1;
|
||||
|
||||
@@ -244,21 +244,21 @@ LogPolar_Overlapping::LogPolar_Overlapping(int w, int h, Point2i center, int R,
|
||||
|
||||
if (sp){
|
||||
int jc=M/2-1, ic=N/2-1;
|
||||
int romax=min(ic, jc);
|
||||
double a=exp(log((double)(romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(a-1)+0.5);
|
||||
int _romax=min(ic, jc);
|
||||
double _a=exp(log((double)(_romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(_a-1)+0.5);
|
||||
}
|
||||
|
||||
create_map(M, N, R, S, ro0);
|
||||
create_map(M, N, _R, _S, _ro0);
|
||||
}
|
||||
|
||||
void LogPolar_Overlapping::create_map(int M, int N, int R, int S, double ro0)
|
||||
void LogPolar_Overlapping::create_map(int _M, int _N, int _R, int _S, double _ro0)
|
||||
{
|
||||
this->M=M;
|
||||
this->N=N;
|
||||
this->R=R;
|
||||
this->S=S;
|
||||
this->ro0=ro0;
|
||||
M=_M;
|
||||
N=_N;
|
||||
R=_R;
|
||||
S=_S;
|
||||
ro0=_ro0;
|
||||
|
||||
int jc=N/2-1, ic=M/2-1;
|
||||
romax=min(ic, jc);
|
||||
@@ -280,14 +280,14 @@ void LogPolar_Overlapping::create_map(int M, int N, int R, int S, double ro0)
|
||||
for(int u=0; u<R; u++)
|
||||
{
|
||||
Rsri.at<float>(v,u)=(float)(ro0*pow(a,u)*sin(v/q)+jc);
|
||||
Csri.at<float>(v,u)=(float)(ro0*pow(a,u)*cos(v/q)+ic);
|
||||
Csri.at<float>(v,u)=(float)(ro0*pow(a,u)*cos(v/q)+ic);
|
||||
Rsr[v*R+u]=(int)floor(Rsri.at<float>(v,u));
|
||||
Csr[v*R+u]=(int)floor(Csri.at<float>(v,u));
|
||||
Csr[v*R+u]=(int)floor(Csri.at<float>(v,u));
|
||||
}
|
||||
}
|
||||
|
||||
bool done=false;
|
||||
|
||||
|
||||
for(int i=0; i<R; i++)
|
||||
{
|
||||
Wsr[i]=ro0*(a-1)*pow(a,i-1);
|
||||
@@ -297,7 +297,7 @@ void LogPolar_Overlapping::create_map(int M, int N, int R, int S, double ro0)
|
||||
done =true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int j=0; j<N; j++)
|
||||
{
|
||||
for(int i=0; i<M; i++)//mdf
|
||||
@@ -312,7 +312,7 @@ void LogPolar_Overlapping::create_map(int M, int N, int R, int S, double ro0)
|
||||
theta+=2*CV_PI;
|
||||
|
||||
ETAyx.at<float>(j,i)=(float)(q*theta);
|
||||
|
||||
|
||||
double ro2=(j-jc)*(j-jc)+(i-ic)*(i-ic);
|
||||
CSIyx.at<float>(j,i)=(float)(0.5*log(ro2/(ro0*ro0))/log(a));
|
||||
}
|
||||
@@ -387,7 +387,7 @@ const Mat LogPolar_Overlapping::to_cartesian(const Mat &source)
|
||||
remap(source_border,out,CSIyx,ETAyx,INTER_LINEAR);
|
||||
|
||||
int wm=w_ker_2D[R-1].w;
|
||||
|
||||
|
||||
vector<double> IMG((N+2*wm+1)*(M+2*wm+1), 0.);
|
||||
vector<double> NOR((N+2*wm+1)*(M+2*wm+1), 0.);
|
||||
|
||||
@@ -426,14 +426,14 @@ const Mat LogPolar_Overlapping::to_cartesian(const Mat &source)
|
||||
Mat out_cropped=out(Range(top,N-1-bottom),Range(left,M-1-right));
|
||||
return out_cropped;
|
||||
}
|
||||
|
||||
|
||||
LogPolar_Overlapping::~LogPolar_Overlapping()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------adjacent---------------------------------------
|
||||
|
||||
LogPolar_Adjacent::LogPolar_Adjacent(int w, int h, Point2i center, int R, double ro0, double smin, int full, int S, int sp)
|
||||
LogPolar_Adjacent::LogPolar_Adjacent(int w, int h, Point2i center, int _R, double _ro0, double smin, int full, int _S, int sp)
|
||||
{
|
||||
if ( (center.x!=w/2 || center.y!=h/2) && full==0) full=1;
|
||||
|
||||
@@ -468,22 +468,22 @@ LogPolar_Adjacent::LogPolar_Adjacent(int w, int h, Point2i center, int R, double
|
||||
|
||||
if (sp){
|
||||
int jc=M/2-1, ic=N/2-1;
|
||||
int romax=min(ic, jc);
|
||||
double a=exp(log((double)(romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(a-1)+0.5);
|
||||
int _romax=min(ic, jc);
|
||||
double _a=exp(log((double)(_romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(_a-1)+0.5);
|
||||
}
|
||||
|
||||
create_map(M, N, R, S, ro0, smin);
|
||||
create_map(M, N, _R, _S, _ro0, smin);
|
||||
}
|
||||
|
||||
|
||||
void LogPolar_Adjacent::create_map(int M, int N, int R, int S, double ro0, double smin)
|
||||
void LogPolar_Adjacent::create_map(int _M, int _N, int _R, int _S, double _ro0, double smin)
|
||||
{
|
||||
LogPolar_Adjacent::M=M;
|
||||
LogPolar_Adjacent::N=N;
|
||||
LogPolar_Adjacent::R=R;
|
||||
LogPolar_Adjacent::S=S;
|
||||
LogPolar_Adjacent::ro0=ro0;
|
||||
M=_M;
|
||||
N=_N;
|
||||
R=_R;
|
||||
S=_S;
|
||||
ro0=_ro0;
|
||||
romax=min(M/2.0, N/2.0);
|
||||
|
||||
a=exp(log(romax/ro0)/(double)R);
|
||||
@@ -507,7 +507,7 @@ void LogPolar_Adjacent::create_map(int M, int N, int R, int S, double ro0, doubl
|
||||
|
||||
|
||||
void LogPolar_Adjacent::subdivide_recursively(double x, double y, int i, int j, double length, double smin)
|
||||
{
|
||||
{
|
||||
if(length<=smin)
|
||||
{
|
||||
int u, v;
|
||||
@@ -576,7 +576,7 @@ const Mat LogPolar_Adjacent::to_cortical(const Mat &source)
|
||||
|
||||
for(int j=0; j<N; j++)
|
||||
for(int i=0; i<M; i++)
|
||||
{
|
||||
{
|
||||
for(size_t z=0; z<(L[M*j+i]).size(); z++)
|
||||
{
|
||||
map[R*((L[M*j+i])[z].v)+((L[M*j+i])[z].u)]+=((L[M*j+i])[z].a)*(source_border.at<uchar>(j,i));
|
||||
@@ -641,7 +641,7 @@ bool LogPolar_Adjacent::get_uv(double x, double y, int&u, int&v)
|
||||
else
|
||||
v= (int) floor(q*(theta+2*CV_PI));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogPolar_Adjacent::~LogPolar_Adjacent()
|
||||
|
@@ -171,9 +171,9 @@ namespace cv
|
||||
{
|
||||
}
|
||||
|
||||
Octree::Octree(const vector<Point3f>& points3d, int maxLevels, int minPoints)
|
||||
Octree::Octree(const vector<Point3f>& points3d, int maxLevels, int _minPoints)
|
||||
{
|
||||
buildTree(points3d, maxLevels, minPoints);
|
||||
buildTree(points3d, maxLevels, _minPoints);
|
||||
}
|
||||
|
||||
Octree::~Octree()
|
||||
@@ -256,12 +256,12 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
void Octree::buildTree(const vector<Point3f>& points3d, int maxLevels, int minPoints)
|
||||
void Octree::buildTree(const vector<Point3f>& points3d, int maxLevels, int _minPoints)
|
||||
{
|
||||
assert((size_t)maxLevels * 8 < MAX_STACK_SIZE);
|
||||
points.resize(points3d.size());
|
||||
std::copy(points3d.begin(), points3d.end(), points.begin());
|
||||
this->minPoints = minPoints;
|
||||
minPoints = _minPoints;
|
||||
|
||||
nodes.clear();
|
||||
nodes.push_back(Node());
|
||||
@@ -275,7 +275,7 @@ namespace cv
|
||||
for (size_t i = 0; i < MAX_LEAFS; i++)
|
||||
root.children[i] = 0;
|
||||
|
||||
if (maxLevels != 1 && (root.end - root.begin) > minPoints)
|
||||
if (maxLevels != 1 && (root.end - root.begin) > _minPoints)
|
||||
{
|
||||
root.isLeaf = false;
|
||||
buildNext(0);
|
||||
|
@@ -75,16 +75,16 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
Retina::Retina(const cv::Size inputSize)
|
||||
Retina::Retina(const cv::Size inputSz)
|
||||
{
|
||||
_retinaFilter = 0;
|
||||
_init(inputSize, true, RETINA_COLOR_BAYER, false);
|
||||
_init(inputSz, true, RETINA_COLOR_BAYER, false);
|
||||
}
|
||||
|
||||
Retina::Retina(const cv::Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
Retina::Retina(const cv::Size inputSz, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
_retinaFilter = 0;
|
||||
_init(inputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
_init(inputSz, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
};
|
||||
|
||||
Retina::~Retina()
|
||||
@@ -342,20 +342,20 @@ const std::valarray<float> & Retina::getMagno() const {return _retinaFilter->get
|
||||
const std::valarray<float> & Retina::getParvo() const {if (_retinaFilter->getColorMode())return _retinaFilter->getColorOutput(); /* implicite else */return _retinaFilter->getContours();}
|
||||
|
||||
// private method called by constructirs
|
||||
void Retina::_init(const cv::Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
void Retina::_init(const cv::Size inputSz, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
// basic error check
|
||||
if (inputSize.height*inputSize.width <= 0)
|
||||
if (inputSz.height*inputSz.width <= 0)
|
||||
throw cv::Exception(-1, "Bad retina size setup : size height and with must be superior to zero", "Retina::setup", "Retina.h", 0);
|
||||
|
||||
unsigned int nbPixels=inputSize.height*inputSize.width;
|
||||
unsigned int nbPixels=inputSz.height*inputSz.width;
|
||||
// resize buffers if size does not match
|
||||
_inputBuffer.resize(nbPixels*3); // buffer supports gray images but also 3 channels color buffers... (larger is better...)
|
||||
|
||||
// allocate the retina model
|
||||
if (_retinaFilter)
|
||||
delete _retinaFilter;
|
||||
_retinaFilter = new RetinaFilter(inputSize.height, inputSize.width, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
_retinaFilter = new RetinaFilter(inputSz.height, inputSz.width, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
|
||||
// prepare the default parameter XML file with default setup
|
||||
setup(_retinaParameters);
|
||||
|
@@ -325,15 +325,15 @@ void RetinaColor::runColorDemultiplexing(const std::valarray<float> &multiplexed
|
||||
|
||||
}else
|
||||
{
|
||||
register const float *multiplexedColorFramePTR= get_data(multiplexedColorFrame);
|
||||
for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance, ++multiplexedColorFramePTR)
|
||||
register const float *multiplexedColorFramePTR1= get_data(multiplexedColorFrame);
|
||||
for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance, ++multiplexedColorFramePTR1)
|
||||
{
|
||||
// normalize by photoreceptors density
|
||||
float Cr=*(chrominancePTR)*_colorLocalDensity[indexc];
|
||||
float Cg=*(chrominancePTR+_filterOutput.getNBpixels())*_colorLocalDensity[indexc+_filterOutput.getNBpixels()];
|
||||
float Cb=*(chrominancePTR+_filterOutput.getDoubleNBpixels())*_colorLocalDensity[indexc+_filterOutput.getDoubleNBpixels()];
|
||||
*luminance=(Cr+Cg+Cb)*_pG;
|
||||
_demultiplexedTempBuffer[_colorSampling[indexc]] = *multiplexedColorFramePTR - *luminance;
|
||||
_demultiplexedTempBuffer[_colorSampling[indexc]] = *multiplexedColorFramePTR1 - *luminance;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -60,9 +60,9 @@ namespace cv
|
||||
using std::min;
|
||||
using std::sqrt;
|
||||
}
|
||||
namespace
|
||||
namespace
|
||||
{
|
||||
const static Scalar colors[] =
|
||||
const static Scalar colors[] =
|
||||
{
|
||||
CV_RGB(255, 0, 0),
|
||||
CV_RGB( 0, 255, 0),
|
||||
@@ -87,21 +87,21 @@ namespace
|
||||
|
||||
template<class FwIt, class T> void iota(FwIt first, FwIt last, T value) { while(first != last) *first++ = value++; }
|
||||
|
||||
void computeNormals( const Octree& Octree, const vector<Point3f>& centers, vector<Point3f>& normals,
|
||||
void computeNormals( const Octree& Octree, const vector<Point3f>& centers, vector<Point3f>& normals,
|
||||
vector<uchar>& mask, float normalRadius, int minNeighbors = 20)
|
||||
{
|
||||
{
|
||||
size_t normals_size = centers.size();
|
||||
normals.resize(normals_size);
|
||||
|
||||
|
||||
if (mask.size() != normals_size)
|
||||
{
|
||||
size_t m = mask.size();
|
||||
size_t m = mask.size();
|
||||
mask.resize(normals_size);
|
||||
if (normals_size > m)
|
||||
for(; m < normals_size; ++m)
|
||||
mask[m] = 1;
|
||||
}
|
||||
|
||||
|
||||
vector<Point3f> buffer;
|
||||
buffer.reserve(128);
|
||||
SVD svd;
|
||||
@@ -132,7 +132,7 @@ void computeNormals( const Octree& Octree, const vector<Point3f>& centers, vecto
|
||||
mean.x /= buf_size;
|
||||
mean.y /= buf_size;
|
||||
mean.z /= buf_size;
|
||||
|
||||
|
||||
double pxpx = 0;
|
||||
double pypy = 0;
|
||||
double pzpz = 0;
|
||||
@@ -162,9 +162,9 @@ void computeNormals( const Octree& Octree, const vector<Point3f>& centers, vecto
|
||||
|
||||
/*normals[n] = Point3f( (float)((double*)svd.vt.data)[6],
|
||||
(float)((double*)svd.vt.data)[7],
|
||||
(float)((double*)svd.vt.data)[8] );*/
|
||||
normals[n] = reinterpret_cast<Point3d*>(svd.vt.data)[2];
|
||||
mask[n] = 1;
|
||||
(float)((double*)svd.vt.data)[8] );*/
|
||||
normals[n] = reinterpret_cast<Point3d*>(svd.vt.data)[2];
|
||||
mask[n] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,22 +213,22 @@ inline __m128 transformSSE(const __m128* matrix, const __m128& in)
|
||||
}
|
||||
|
||||
inline __m128i _mm_mullo_epi32_emul(const __m128i& a, __m128i& b)
|
||||
{
|
||||
{
|
||||
__m128i pack = _mm_packs_epi32(a, a);
|
||||
return _mm_unpacklo_epi16(_mm_mullo_epi16(pack, b), _mm_mulhi_epi16(pack, b));
|
||||
return _mm_unpacklo_epi16(_mm_mullo_epi16(pack, b), _mm_mulhi_epi16(pack, b));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, const vector<Point3f>& normals,
|
||||
void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, const vector<Point3f>& normals,
|
||||
vector<uchar>& mask, Mat& spinImages, int imageWidth, float binSize)
|
||||
{
|
||||
{
|
||||
float pixelsPerMeter = 1.f / binSize;
|
||||
float support = imageWidth * binSize;
|
||||
|
||||
float support = imageWidth * binSize;
|
||||
|
||||
assert(normals.size() == points.size());
|
||||
assert(mask.size() == points.size());
|
||||
|
||||
|
||||
size_t points_size = points.size();
|
||||
mask.resize(points_size);
|
||||
|
||||
@@ -257,7 +257,7 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
|
||||
int t = cvGetThreadNum();
|
||||
vector<Point3f>& pointsInSphere = pointsInSpherePool[t];
|
||||
|
||||
|
||||
const Point3f& center = points[i];
|
||||
Octree.getPointsWithinSphere(center, searchRad, pointsInSphere);
|
||||
|
||||
@@ -269,7 +269,7 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
}
|
||||
|
||||
const Point3f& normal = normals[i];
|
||||
|
||||
|
||||
float rotmat[9];
|
||||
initRotationMat(normal, rotmat);
|
||||
Point3f new_center;
|
||||
@@ -287,7 +287,7 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
{
|
||||
__m128 rotmatSSE[3];
|
||||
convertTransformMatrix(rotmat, (float*)rotmatSSE);
|
||||
|
||||
|
||||
__m128 center_x4 = _mm_set1_ps(new_center.x);
|
||||
__m128 center_y4 = _mm_set1_ps(new_center.y);
|
||||
__m128 center_z4 = _mm_set1_ps(new_center.z + halfSuppport);
|
||||
@@ -313,7 +313,7 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
__m128 z0 = _mm_unpackhi_ps(pt0, pt1); // z0 z1 . .
|
||||
__m128 z1 = _mm_unpackhi_ps(pt2, pt3); // z2 z3 . .
|
||||
__m128 beta4 = _mm_sub_ps(center_z4, _mm_movelh_ps(z0, z1)); // b0 b1 b2 b3
|
||||
|
||||
|
||||
__m128 xy0 = _mm_unpacklo_ps(pt0, pt1); // x0 x1 y0 y1
|
||||
__m128 xy1 = _mm_unpacklo_ps(pt2, pt3); // x2 x3 y2 y3
|
||||
__m128 x4 = _mm_movelh_ps(xy0, xy1); // x0 x1 x2 x3
|
||||
@@ -322,7 +322,7 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
x4 = _mm_sub_ps(x4, center_x4);
|
||||
y4 = _mm_sub_ps(y4, center_y4);
|
||||
__m128 alpha4 = _mm_sqrt_ps(_mm_add_ps(_mm_mul_ps(x4,x4),_mm_mul_ps(y4,y4)));
|
||||
|
||||
|
||||
__m128 n1f4 = _mm_mul_ps( beta4, ppm4); /* beta4 float */
|
||||
__m128 n2f4 = _mm_mul_ps(alpha4, ppm4); /* alpha4 float */
|
||||
|
||||
@@ -333,21 +333,21 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
__m128 f1 = _mm_sub_ps( n1f4, _mm_cvtepi32_ps(n1) ); /* { beta4 } */
|
||||
__m128 f2 = _mm_sub_ps( n2f4, _mm_cvtepi32_ps(n2) ); /* { alpha4 } */
|
||||
|
||||
__m128 f1f2 = _mm_mul_ps(f1, f2); // f1 * f2
|
||||
__m128 f1f2 = _mm_mul_ps(f1, f2); // f1 * f2
|
||||
__m128 omf1omf2 = _mm_add_ps(_mm_sub_ps(_mm_sub_ps(one4f, f2), f1), f1f2); // (1-f1) * (1-f2)
|
||||
|
||||
__m128i mask = _mm_and_si128(
|
||||
|
||||
__m128i _mask = _mm_and_si128(
|
||||
_mm_andnot_si128(_mm_cmpgt_epi32(zero4, n1), _mm_cmpgt_epi32(height4m1, n1)),
|
||||
_mm_andnot_si128(_mm_cmpgt_epi32(zero4, n2), _mm_cmpgt_epi32(width4m1, n2)));
|
||||
|
||||
__m128 maskf = _mm_cmpneq_ps(_mm_cvtepi32_ps(mask), zero4f);
|
||||
|
||||
__m128 maskf = _mm_cmpneq_ps(_mm_cvtepi32_ps(_mask), zero4f);
|
||||
|
||||
__m128 v00 = _mm_and_ps( omf1omf2 , maskf); // a00 b00 c00 d00
|
||||
__m128 v01 = _mm_and_ps( _mm_sub_ps( f2, f1f2 ), maskf); // a01 b01 c01 d01
|
||||
__m128 v10 = _mm_and_ps( _mm_sub_ps( f1, f1f2 ), maskf); // a10 b10 c10 d10
|
||||
__m128 v11 = _mm_and_ps( f1f2 , maskf); // a11 b11 c11 d11
|
||||
|
||||
__m128i ofs4 = _mm_and_si128(_mm_add_epi32(_mm_mullo_epi32_emul(n1, step4), n2), mask);
|
||||
__m128i ofs4 = _mm_and_si128(_mm_add_epi32(_mm_mullo_epi32_emul(n1, step4), n2), _mask);
|
||||
_mm_store_si128((__m128i*)o, ofs4);
|
||||
|
||||
__m128 t0 = _mm_unpacklo_ps(v00, v01); // a00 a01 b00 b01
|
||||
@@ -395,9 +395,9 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
if (beta >= support || beta < 0)
|
||||
continue;
|
||||
|
||||
alpha = sqrt( (new_center.x - pt.x) * (new_center.x - pt.x) +
|
||||
(new_center.y - pt.y) * (new_center.y - pt.y) );
|
||||
|
||||
alpha = sqrt( (new_center.x - pt.x) * (new_center.x - pt.x) +
|
||||
(new_center.y - pt.y) * (new_center.y - pt.y) );
|
||||
|
||||
float n1f = beta * pixelsPerMeter;
|
||||
float n2f = alpha * pixelsPerMeter;
|
||||
|
||||
@@ -407,7 +407,7 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
float f1 = n1f - n1;
|
||||
float f2 = n2f - n2;
|
||||
|
||||
if ((unsigned)n1 >= (unsigned)(spinImage.rows-1) ||
|
||||
if ((unsigned)n1 >= (unsigned)(spinImage.rows-1) ||
|
||||
(unsigned)n2 >= (unsigned)(spinImage.cols-1))
|
||||
continue;
|
||||
|
||||
@@ -454,27 +454,27 @@ float cv::Mesh3D::estimateResolution(float /*tryRatio*/)
|
||||
|
||||
vector<double> dist(tryNum * neighbors);
|
||||
vector<int> inds(tryNum * neighbors);
|
||||
vector<Point3f> query;
|
||||
vector<Point3f> query;
|
||||
|
||||
RNG& rng = theRNG();
|
||||
RNG& rng = theRNG();
|
||||
for(int i = 0; i < tryNum; ++i)
|
||||
query.push_back(vtx[rng.next() % vtx.size()]);
|
||||
|
||||
|
||||
CvMat cvinds = cvMat( (int)tryNum, neighbors, CV_32S, &inds[0] );
|
||||
CvMat cvdist = cvMat( (int)tryNum, neighbors, CV_64F, &dist[0] );
|
||||
CvMat cvdist = cvMat( (int)tryNum, neighbors, CV_64F, &dist[0] );
|
||||
CvMat cvquery = cvMat( (int)tryNum, 3, CV_32F, &query[0] );
|
||||
cvFindFeatures(tr, &cvquery, &cvinds, &cvdist, neighbors, 50);
|
||||
cvFindFeatures(tr, &cvquery, &cvinds, &cvdist, neighbors, 50);
|
||||
cvReleaseFeatureTree(tr);
|
||||
|
||||
const int invalid_dist = -2;
|
||||
const int invalid_dist = -2;
|
||||
for(int i = 0; i < tryNum; ++i)
|
||||
if (inds[i] == -1)
|
||||
dist[i] = invalid_dist;
|
||||
|
||||
dist.resize(remove(dist.begin(), dist.end(), invalid_dist) - dist.begin());
|
||||
|
||||
|
||||
sort(dist, less<double>());
|
||||
|
||||
|
||||
return resolution = (float)dist[ dist.size() / 2 ];
|
||||
#else
|
||||
CV_Error(CV_StsNotImplemented, "");
|
||||
@@ -494,7 +494,7 @@ void cv::Mesh3D::computeNormals(const vector<int>& subset, float normalRadius, i
|
||||
{
|
||||
buildOctree();
|
||||
vector<uchar> mask(vtx.size(), 0);
|
||||
for(size_t i = 0; i < subset.size(); ++i)
|
||||
for(size_t i = 0; i < subset.size(); ++i)
|
||||
mask[subset[i]] = 1;
|
||||
::computeNormals(octree, vtx, normals, mask, normalRadius, minNeighbors);
|
||||
}
|
||||
@@ -504,31 +504,31 @@ void cv::Mesh3D::writeAsVrml(const String& file, const vector<Scalar>& _colors)
|
||||
ofstream ofs(file.c_str());
|
||||
|
||||
ofs << "#VRML V2.0 utf8" << endl;
|
||||
ofs << "Shape" << std::endl << "{" << endl;
|
||||
ofs << "geometry PointSet" << endl << "{" << endl;
|
||||
ofs << "coord Coordinate" << endl << "{" << endl;
|
||||
ofs << "point[" << endl;
|
||||
ofs << "Shape" << std::endl << "{" << endl;
|
||||
ofs << "geometry PointSet" << endl << "{" << endl;
|
||||
ofs << "coord Coordinate" << endl << "{" << endl;
|
||||
ofs << "point[" << endl;
|
||||
|
||||
for(size_t i = 0; i < vtx.size(); ++i)
|
||||
ofs << vtx[i].x << " " << vtx[i].y << " " << vtx[i].z << endl;
|
||||
|
||||
ofs << "]" << endl; //point[
|
||||
ofs << "}" << endl; //Coordinate{
|
||||
|
||||
ofs << "]" << endl; //point[
|
||||
ofs << "}" << endl; //Coordinate{
|
||||
|
||||
if (vtx.size() == _colors.size())
|
||||
{
|
||||
ofs << "color Color" << endl << "{" << endl;
|
||||
ofs << "color[" << endl;
|
||||
|
||||
|
||||
for(size_t i = 0; i < _colors.size(); ++i)
|
||||
ofs << (float)_colors[i][2] << " " << (float)_colors[i][1] << " " << (float)_colors[i][0] << endl;
|
||||
|
||||
|
||||
ofs << "]" << endl; //color[
|
||||
ofs << "}" << endl; //color Color{
|
||||
ofs << "}" << endl; //color Color{
|
||||
}
|
||||
|
||||
ofs << "}" << endl; //PointSet{
|
||||
ofs << "}" << endl; //Shape{
|
||||
ofs << "}" << endl; //PointSet{
|
||||
ofs << "}" << endl; //Shape{
|
||||
}
|
||||
|
||||
|
||||
@@ -538,45 +538,45 @@ void cv::Mesh3D::writeAsVrml(const String& file, const vector<Scalar>& _colors)
|
||||
bool cv::SpinImageModel::spinCorrelation(const Mat& spin1, const Mat& spin2, float lambda, float& result)
|
||||
{
|
||||
struct Math { static double atanh(double x) { return 0.5 * std::log( (1 + x) / (1 - x) ); } };
|
||||
|
||||
|
||||
const float* s1 = spin1.ptr<float>();
|
||||
const float* s2 = spin2.ptr<float>();
|
||||
|
||||
int spin_sz = spin1.cols * spin1.rows;
|
||||
int spin_sz = spin1.cols * spin1.rows;
|
||||
double sum1 = 0.0, sum2 = 0.0, sum12 = 0.0, sum11 = 0.0, sum22 = 0.0;
|
||||
|
||||
int N = 0;
|
||||
int i = 0;
|
||||
#if CV_SSE2//____________TEMPORARY_DISABLED_____________
|
||||
float CV_DECL_ALIGNED(16) su1[4], su2[4], su11[4], su22[4], su12[4], n[4];
|
||||
|
||||
float CV_DECL_ALIGNED(16) su1[4], su2[4], su11[4], su22[4], su12[4], n[4];
|
||||
|
||||
__m128 zerof4 = _mm_setzero_ps();
|
||||
__m128 onef4 = _mm_set1_ps(1.f);
|
||||
__m128 Nf4 = zerof4;
|
||||
__m128 Nf4 = zerof4;
|
||||
__m128 sum1f4 = zerof4;
|
||||
__m128 sum2f4 = zerof4;
|
||||
__m128 sum11f4 = zerof4;
|
||||
__m128 sum22f4 = zerof4;
|
||||
__m128 sum12f4 = zerof4;
|
||||
__m128 sum12f4 = zerof4;
|
||||
for(; i < spin_sz - 5; i += 4)
|
||||
{
|
||||
__m128 v1f4 = _mm_loadu_ps(s1 + i);
|
||||
__m128 v2f4 = _mm_loadu_ps(s2 + i);
|
||||
__m128 v1f4 = _mm_loadu_ps(s1 + i);
|
||||
__m128 v2f4 = _mm_loadu_ps(s2 + i);
|
||||
|
||||
__m128 mskf4 = _mm_and_ps(_mm_cmpneq_ps(v1f4, zerof4), _mm_cmpneq_ps(v2f4, zerof4));
|
||||
if( !_mm_movemask_ps(mskf4) )
|
||||
if( !_mm_movemask_ps(mskf4) )
|
||||
continue;
|
||||
|
||||
|
||||
Nf4 = _mm_add_ps(Nf4, _mm_and_ps(onef4, mskf4));
|
||||
|
||||
v1f4 = _mm_and_ps(v1f4, mskf4);
|
||||
v2f4 = _mm_and_ps(v2f4, mskf4);
|
||||
|
||||
|
||||
sum1f4 = _mm_add_ps(sum1f4, v1f4);
|
||||
sum2f4 = _mm_add_ps(sum2f4, v2f4);
|
||||
sum11f4 = _mm_add_ps(sum11f4, _mm_mul_ps(v1f4, v1f4));
|
||||
sum22f4 = _mm_add_ps(sum22f4, _mm_mul_ps(v2f4, v2f4));
|
||||
sum12f4 = _mm_add_ps(sum12f4, _mm_mul_ps(v1f4, v2f4));
|
||||
sum12f4 = _mm_add_ps(sum12f4, _mm_mul_ps(v1f4, v2f4));
|
||||
}
|
||||
_mm_store_ps( su1, sum1f4 );
|
||||
_mm_store_ps( su2, sum2f4 );
|
||||
@@ -601,11 +601,11 @@ bool cv::SpinImageModel::spinCorrelation(const Mat& spin1, const Mat& spin2, flo
|
||||
if( !v1 || !v2 )
|
||||
continue;
|
||||
N++;
|
||||
|
||||
sum1 += v1;
|
||||
sum2 += v2;
|
||||
sum11 += v1 * v1;
|
||||
sum22 += v2 * v2;
|
||||
|
||||
sum1 += v1;
|
||||
sum2 += v2;
|
||||
sum11 += v1 * v1;
|
||||
sum22 += v2 * v2;
|
||||
sum12 += v1 * v2;
|
||||
}
|
||||
if( N < 4 )
|
||||
@@ -624,13 +624,13 @@ bool cv::SpinImageModel::spinCorrelation(const Mat& spin1, const Mat& spin2, flo
|
||||
double corr = (Nsum12 - sum1 * sum2) / sqrt( (Nsum11 - sum1sum1) * (Nsum22 - sum2sum2) );
|
||||
double atanh = Math::atanh(corr);
|
||||
result = (float)( atanh * atanh - lambda * ( 1.0 / (N - 3) ) );
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Point2f cv::SpinImageModel::calcSpinMapCoo(const Point3f& p, const Point3f& v, const Point3f& n)
|
||||
{
|
||||
/*Point3f PmV(p.x - v.x, p.y - v.y, p.z - v.z);
|
||||
float normalNorm = (float)norm(n);
|
||||
{
|
||||
/*Point3f PmV(p.x - v.x, p.y - v.y, p.z - v.z);
|
||||
float normalNorm = (float)norm(n);
|
||||
float beta = PmV.dot(n) / normalNorm;
|
||||
float pmcNorm = (float)norm(PmV);
|
||||
float alpha = sqrt( pmcNorm * pmcNorm - beta * beta);
|
||||
@@ -639,23 +639,23 @@ inline Point2f cv::SpinImageModel::calcSpinMapCoo(const Point3f& p, const Point3
|
||||
float pmv_x = p.x - v.x, pmv_y = p.y - v.y, pmv_z = p.z - v.z;
|
||||
|
||||
float beta = (pmv_x * n.x + pmv_y + n.y + pmv_z * n.z) / sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
|
||||
float alpha = sqrt( pmv_x * pmv_x + pmv_y * pmv_y + pmv_z * pmv_z - beta * beta);
|
||||
float alpha = sqrt( pmv_x * pmv_x + pmv_y * pmv_y + pmv_z * pmv_z - beta * beta);
|
||||
return Point2f(alpha, beta);
|
||||
}
|
||||
|
||||
inline float cv::SpinImageModel::geometricConsistency(const Point3f& pointScene1, const Point3f& normalScene1,
|
||||
const Point3f& pointModel1, const Point3f& normalModel1,
|
||||
const Point3f& pointScene2, const Point3f& normalScene2,
|
||||
const Point3f& pointScene2, const Point3f& normalScene2,
|
||||
const Point3f& pointModel2, const Point3f& normalModel2)
|
||||
{
|
||||
{
|
||||
Point2f Sm2_to_m1, Ss2_to_s1;
|
||||
Point2f Sm1_to_m2, Ss1_to_s2;
|
||||
|
||||
double n_Sm2_to_m1 = norm(Sm2_to_m1 = calcSpinMapCoo(pointModel2, pointModel1, normalModel1));
|
||||
double n_Ss2_to_s1 = norm(Ss2_to_s1 = calcSpinMapCoo(pointScene2, pointScene1, normalScene1));
|
||||
double n_Ss2_to_s1 = norm(Ss2_to_s1 = calcSpinMapCoo(pointScene2, pointScene1, normalScene1));
|
||||
|
||||
double gc21 = 2 * norm(Sm2_to_m1 - Ss2_to_s1) / (n_Sm2_to_m1 + n_Ss2_to_s1 ) ;
|
||||
|
||||
|
||||
double n_Sm1_to_m2 = norm(Sm1_to_m2 = calcSpinMapCoo(pointModel1, pointModel2, normalModel2));
|
||||
double n_Ss1_to_s2 = norm(Ss1_to_s2 = calcSpinMapCoo(pointScene1, pointScene2, normalScene2));
|
||||
|
||||
@@ -666,10 +666,10 @@ inline float cv::SpinImageModel::geometricConsistency(const Point3f& pointScene1
|
||||
|
||||
inline float cv::SpinImageModel::groupingCreteria(const Point3f& pointScene1, const Point3f& normalScene1,
|
||||
const Point3f& pointModel1, const Point3f& normalModel1,
|
||||
const Point3f& pointScene2, const Point3f& normalScene2,
|
||||
const Point3f& pointModel2, const Point3f& normalModel2,
|
||||
const Point3f& pointScene2, const Point3f& normalScene2,
|
||||
const Point3f& pointModel2, const Point3f& normalModel2,
|
||||
float gamma)
|
||||
{
|
||||
{
|
||||
Point2f Sm2_to_m1, Ss2_to_s1;
|
||||
Point2f Sm1_to_m2, Ss1_to_s2;
|
||||
|
||||
@@ -680,7 +680,7 @@ inline float cv::SpinImageModel::groupingCreteria(const Point3f& pointScene1, co
|
||||
|
||||
double gc21 = 2 * norm(Sm2_to_m1 - Ss2_to_s1) / (n_Sm2_to_m1 + n_Ss2_to_s1 );
|
||||
double wgc21 = gc21 / (1 - exp( -(n_Sm2_to_m1 + n_Ss2_to_s1) * gamma05_inv ) );
|
||||
|
||||
|
||||
double n_Sm1_to_m2 = norm(Sm1_to_m2 = calcSpinMapCoo(pointModel1, pointModel2, normalModel2));
|
||||
double n_Ss1_to_s2 = norm(Ss1_to_s2 = calcSpinMapCoo(pointScene1, pointScene2, normalScene2));
|
||||
|
||||
@@ -692,10 +692,10 @@ inline float cv::SpinImageModel::groupingCreteria(const Point3f& pointScene1, co
|
||||
|
||||
|
||||
cv::SpinImageModel::SpinImageModel(const Mesh3D& _mesh) : mesh(_mesh) , out(0)
|
||||
{
|
||||
{
|
||||
if (mesh.vtx.empty())
|
||||
throw Mesh3D::EmptyMeshException();
|
||||
defaultParams();
|
||||
defaultParams();
|
||||
}
|
||||
cv::SpinImageModel::SpinImageModel() : out(0) { defaultParams(); }
|
||||
cv::SpinImageModel::~SpinImageModel() {}
|
||||
@@ -708,8 +708,8 @@ void cv::SpinImageModel::defaultParams()
|
||||
minNeighbors = 20;
|
||||
|
||||
binSize = 0.f; /* autodetect according to mesh resolution */
|
||||
imageWidth = 32;
|
||||
|
||||
imageWidth = 32;
|
||||
|
||||
lambda = 0.f; /* autodetect according to medan non zero images bin */
|
||||
gamma = 0.f; /* autodetect according to mesh resolution */
|
||||
|
||||
@@ -725,28 +725,28 @@ Mat cv::SpinImageModel::packRandomScaledSpins(bool separateScale, size_t xCount,
|
||||
if (num == 0)
|
||||
return Mat();
|
||||
|
||||
RNG& rng = theRNG();
|
||||
RNG& rng = theRNG();
|
||||
|
||||
vector<Mat> spins;
|
||||
for(int i = 0; i < num; ++i)
|
||||
spins.push_back(getSpinImage( rng.next() % spinNum ).reshape(1, imageWidth));
|
||||
|
||||
spins.push_back(getSpinImage( rng.next() % spinNum ).reshape(1, imageWidth));
|
||||
|
||||
if (separateScale)
|
||||
for(int i = 0; i < num; ++i)
|
||||
{
|
||||
double max;
|
||||
Mat spin8u;
|
||||
minMaxLoc(spins[i], 0, &max);
|
||||
minMaxLoc(spins[i], 0, &max);
|
||||
spins[i].convertTo(spin8u, CV_8U, -255.0/max, 255.0);
|
||||
spins[i] = spin8u;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
double totalMax = 0;
|
||||
for(int i = 0; i < num; ++i)
|
||||
{
|
||||
double m;
|
||||
minMaxLoc(spins[i], 0, &m);
|
||||
minMaxLoc(spins[i], 0, &m);
|
||||
totalMax = max(m, totalMax);
|
||||
}
|
||||
|
||||
@@ -760,12 +760,12 @@ Mat cv::SpinImageModel::packRandomScaledSpins(bool separateScale, size_t xCount,
|
||||
|
||||
int sz = spins.front().cols;
|
||||
|
||||
Mat result((int)(yCount * sz + (yCount - 1)), (int)(xCount * sz + (xCount - 1)), CV_8UC3);
|
||||
Mat result((int)(yCount * sz + (yCount - 1)), (int)(xCount * sz + (xCount - 1)), CV_8UC3);
|
||||
result = colors[(static_cast<int64>(cvGetTickCount()/cvGetTickFrequency())/1000) % colors_mum];
|
||||
|
||||
int pos = 0;
|
||||
for(int y = 0; y < (int)yCount; ++y)
|
||||
for(int x = 0; x < (int)xCount; ++x)
|
||||
for(int x = 0; x < (int)xCount; ++x)
|
||||
if (pos < num)
|
||||
{
|
||||
int starty = (y + 0) * sz + y;
|
||||
@@ -778,7 +778,7 @@ Mat cv::SpinImageModel::packRandomScaledSpins(bool separateScale, size_t xCount,
|
||||
cvtColor(spins[pos++], color, CV_GRAY2BGR);
|
||||
Mat roi = result(Range(starty, endy), Range(startx, endx));
|
||||
color.copyTo(roi);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -811,8 +811,8 @@ void cv::SpinImageModel::selectRandomSubset(float ratio)
|
||||
int pos = rnd.next() % left.size();
|
||||
subset[i] = (int)left[pos];
|
||||
|
||||
left[pos] = left.back();
|
||||
left.resize(left.size() - 1);
|
||||
left[pos] = left.back();
|
||||
left.resize(left.size() - 1);
|
||||
}
|
||||
sort(subset, less<int>());
|
||||
}
|
||||
@@ -823,21 +823,21 @@ void cv::SpinImageModel::setSubset(const vector<int>& ss)
|
||||
subset = ss;
|
||||
}
|
||||
|
||||
void cv::SpinImageModel::repackSpinImages(const vector<uchar>& mask, Mat& spinImages, bool reAlloc) const
|
||||
{
|
||||
void cv::SpinImageModel::repackSpinImages(const vector<uchar>& mask, Mat& _spinImages, bool reAlloc) const
|
||||
{
|
||||
if (reAlloc)
|
||||
{
|
||||
size_t spinCount = mask.size() - count(mask.begin(), mask.end(), (uchar)0);
|
||||
Mat newImgs((int)spinCount, spinImages.cols, spinImages.type());
|
||||
Mat newImgs((int)spinCount, _spinImages.cols, _spinImages.type());
|
||||
|
||||
int pos = 0;
|
||||
for(size_t t = 0; t < mask.size(); ++t)
|
||||
if (mask[t])
|
||||
{
|
||||
Mat row = newImgs.row(pos++);
|
||||
spinImages.row((int)t).copyTo(row);
|
||||
_spinImages.row((int)t).copyTo(row);
|
||||
}
|
||||
spinImages = newImgs;
|
||||
_spinImages = newImgs;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -849,13 +849,13 @@ void cv::SpinImageModel::repackSpinImages(const vector<uchar>& mask, Mat& spinIm
|
||||
|
||||
int first = dest + 1;
|
||||
for (; first != last; ++first)
|
||||
if (mask[first] != 0)
|
||||
if (mask[first] != 0)
|
||||
{
|
||||
Mat row = spinImages.row(dest);
|
||||
spinImages.row(first).copyTo(row);
|
||||
Mat row = _spinImages.row(dest);
|
||||
_spinImages.row(first).copyTo(row);
|
||||
++dest;
|
||||
}
|
||||
spinImages = spinImages.rowRange(0, dest);
|
||||
_spinImages = _spinImages.rowRange(0, dest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,13 +865,13 @@ void cv::SpinImageModel::compute()
|
||||
if (binSize == 0.f)
|
||||
{
|
||||
if (mesh.resolution == -1.f)
|
||||
mesh.estimateResolution();
|
||||
mesh.estimateResolution();
|
||||
binSize = mesh.resolution;
|
||||
}
|
||||
/* estimate normalRadius */
|
||||
normalRadius = normalRadius != 0.f ? normalRadius : binSize * imageWidth / 2;
|
||||
/* estimate normalRadius */
|
||||
normalRadius = normalRadius != 0.f ? normalRadius : binSize * imageWidth / 2;
|
||||
|
||||
mesh.buildOctree();
|
||||
mesh.buildOctree();
|
||||
if (subset.empty())
|
||||
{
|
||||
mesh.computeNormals(normalRadius, minNeighbors);
|
||||
@@ -881,16 +881,16 @@ void cv::SpinImageModel::compute()
|
||||
else
|
||||
mesh.computeNormals(subset, normalRadius, minNeighbors);
|
||||
|
||||
vector<uchar> mask(mesh.vtx.size(), 0);
|
||||
vector<uchar> mask(mesh.vtx.size(), 0);
|
||||
for(size_t i = 0; i < subset.size(); ++i)
|
||||
if (mesh.normals[subset[i]] == Mesh3D::allzero)
|
||||
subset[i] = -1;
|
||||
if (mesh.normals[subset[i]] == Mesh3D::allzero)
|
||||
subset[i] = -1;
|
||||
else
|
||||
mask[subset[i]] = 1;
|
||||
subset.resize( remove(subset.begin(), subset.end(), -1) - subset.begin() );
|
||||
|
||||
|
||||
vector<Point3f> vtx;
|
||||
vector<Point3f> normals;
|
||||
vector<Point3f> normals;
|
||||
for(size_t i = 0; i < mask.size(); ++i)
|
||||
if(mask[i])
|
||||
{
|
||||
@@ -906,7 +906,7 @@ void cv::SpinImageModel::compute()
|
||||
for(size_t i = 0; i < mask.size(); ++i)
|
||||
if(mask[i])
|
||||
if (spinMask[mask_pos++] == 0)
|
||||
subset.resize( remove(subset.begin(), subset.end(), (int)i) - subset.begin() );
|
||||
subset.resize( remove(subset.begin(), subset.end(), (int)i) - subset.begin() );
|
||||
}
|
||||
|
||||
void cv::SpinImageModel::matchSpinToModel(const Mat& spin, vector<int>& indeces, vector<float>& corrCoeffs, bool useExtremeOutliers) const
|
||||
@@ -920,46 +920,46 @@ void cv::SpinImageModel::matchSpinToModel(const Mat& spin, vector<int>& indeces,
|
||||
vector<uchar> masks(model.spinImages.rows);
|
||||
vector<float> cleanCorrs;
|
||||
cleanCorrs.reserve(model.spinImages.rows);
|
||||
|
||||
|
||||
for(int i = 0; i < model.spinImages.rows; ++i)
|
||||
{
|
||||
masks[i] = spinCorrelation(spin, model.spinImages.row(i), model.lambda, corrs[i]);
|
||||
masks[i] = spinCorrelation(spin, model.spinImages.row(i), model.lambda, corrs[i]);
|
||||
if (masks[i])
|
||||
cleanCorrs.push_back(corrs[i]);
|
||||
}
|
||||
|
||||
|
||||
/* Filtering by measure histogram */
|
||||
size_t total = cleanCorrs.size();
|
||||
if(total < 5)
|
||||
return;
|
||||
|
||||
sort(cleanCorrs, less<float>());
|
||||
|
||||
|
||||
float lower_fourth = cleanCorrs[(1 * total) / 4 - 1];
|
||||
float upper_fourth = cleanCorrs[(3 * total) / 4 - 0];
|
||||
float fourth_spread = upper_fourth - lower_fourth;
|
||||
|
||||
//extreme or moderate?
|
||||
float coef = useExtremeOutliers ? 3.0f : 1.5f;
|
||||
float coef = useExtremeOutliers ? 3.0f : 1.5f;
|
||||
|
||||
float histThresHi = upper_fourth + coef * fourth_spread;
|
||||
//float histThresLo = lower_fourth - coef * fourth_spread;
|
||||
|
||||
float histThresHi = upper_fourth + coef * fourth_spread;
|
||||
//float histThresLo = lower_fourth - coef * fourth_spread;
|
||||
|
||||
for(size_t i = 0; i < corrs.size(); ++i)
|
||||
if (masks[i])
|
||||
if (/* corrs[i] < histThresLo || */ corrs[i] > histThresHi)
|
||||
{
|
||||
indeces.push_back((int)i);
|
||||
corrCoeffs.push_back(corrs[i]);
|
||||
corrCoeffs.push_back(corrs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
namespace
|
||||
{
|
||||
|
||||
struct Match
|
||||
{
|
||||
int sceneInd;
|
||||
int sceneInd;
|
||||
int modelInd;
|
||||
float measure;
|
||||
|
||||
@@ -984,7 +984,7 @@ struct WgcHelper
|
||||
{
|
||||
const float* wgcLine = mat.ptr<float>((int)corespInd);
|
||||
float maximum = numeric_limits<float>::min();
|
||||
|
||||
|
||||
for(citer pos = group.begin(); pos != group.end(); ++pos)
|
||||
maximum = max(wgcLine[*pos], maximum);
|
||||
|
||||
@@ -997,7 +997,7 @@ private:
|
||||
}
|
||||
|
||||
void cv::SpinImageModel::match(const SpinImageModel& scene, vector< vector<Vec2i> >& result)
|
||||
{
|
||||
{
|
||||
if (mesh.vtx.empty())
|
||||
throw Mesh3D::EmptyMeshException();
|
||||
|
||||
@@ -1006,25 +1006,25 @@ private:
|
||||
SpinImageModel& model = *this;
|
||||
const float infinity = numeric_limits<float>::infinity();
|
||||
const float float_max = numeric_limits<float>::max();
|
||||
|
||||
|
||||
/* estimate gamma */
|
||||
if (model.gamma == 0.f)
|
||||
{
|
||||
if (model.mesh.resolution == -1.f)
|
||||
model.mesh.estimateResolution();
|
||||
model.mesh.estimateResolution();
|
||||
model.gamma = 4 * model.mesh.resolution;
|
||||
}
|
||||
|
||||
/* estimate lambda */
|
||||
if (model.lambda == 0.f)
|
||||
{
|
||||
vector<int> nonzero(model.spinImages.rows);
|
||||
vector<int> nonzero(model.spinImages.rows);
|
||||
for(int i = 0; i < model.spinImages.rows; ++i)
|
||||
nonzero[i] = countNonZero(model.spinImages.row(i));
|
||||
sort(nonzero, less<int>());
|
||||
model.lambda = static_cast<float>( nonzero[ nonzero.size()/2 ] ) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TickMeter corr_timer;
|
||||
corr_timer.start();
|
||||
vector<Match> allMatches;
|
||||
@@ -1032,37 +1032,37 @@ private:
|
||||
{
|
||||
vector<int> indeces;
|
||||
vector<float> coeffs;
|
||||
matchSpinToModel(scene.spinImages.row(i), indeces, coeffs);
|
||||
matchSpinToModel(scene.spinImages.row(i), indeces, coeffs);
|
||||
for(size_t t = 0; t < indeces.size(); ++t)
|
||||
allMatches.push_back(Match(i, indeces[t], coeffs[t]));
|
||||
allMatches.push_back(Match(i, indeces[t], coeffs[t]));
|
||||
|
||||
if (out) if (i % 100 == 0) *out << "Comparing scene spinimage " << i << " of " << scene.spinImages.rows << endl;
|
||||
if (out) if (i % 100 == 0) *out << "Comparing scene spinimage " << i << " of " << scene.spinImages.rows << endl;
|
||||
}
|
||||
corr_timer.stop();
|
||||
if (out) *out << "Spin correlation time = " << corr_timer << endl;
|
||||
if (out) *out << "Matches number = " << allMatches.size() << endl;
|
||||
|
||||
if(allMatches.empty())
|
||||
if(allMatches.empty())
|
||||
return;
|
||||
|
||||
|
||||
/* filtering by similarity measure */
|
||||
const float fraction = 0.5f;
|
||||
float maxMeasure = max_element(allMatches.begin(), allMatches.end(), less<float>())->measure;
|
||||
float maxMeasure = max_element(allMatches.begin(), allMatches.end(), less<float>())->measure;
|
||||
allMatches.erase(
|
||||
remove_if(allMatches.begin(), allMatches.end(), bind2nd(less<float>(), maxMeasure * fraction)),
|
||||
remove_if(allMatches.begin(), allMatches.end(), bind2nd(less<float>(), maxMeasure * fraction)),
|
||||
allMatches.end());
|
||||
if (out) *out << "Matches number [filtered by similarity measure] = " << allMatches.size() << endl;
|
||||
|
||||
int matchesSize = (int)allMatches.size();
|
||||
if(matchesSize == 0)
|
||||
return;
|
||||
|
||||
/* filtering by geometric consistency */
|
||||
|
||||
/* filtering by geometric consistency */
|
||||
for(int i = 0; i < matchesSize; ++i)
|
||||
{
|
||||
int consistNum = 1;
|
||||
float gc = float_max;
|
||||
|
||||
|
||||
for(int j = 0; j < matchesSize; ++j)
|
||||
if (i != j)
|
||||
{
|
||||
@@ -1075,31 +1075,31 @@ private:
|
||||
{
|
||||
const Point3f& pointSceneI = scene.getSpinVertex(mi.sceneInd);
|
||||
const Point3f& normalSceneI = scene.getSpinNormal(mi.sceneInd);
|
||||
|
||||
|
||||
const Point3f& pointModelI = model.getSpinVertex(mi.modelInd);
|
||||
const Point3f& normalModelI = model.getSpinNormal(mi.modelInd);
|
||||
|
||||
|
||||
const Point3f& pointSceneJ = scene.getSpinVertex(mj.sceneInd);
|
||||
const Point3f& normalSceneJ = scene.getSpinNormal(mj.sceneInd);
|
||||
|
||||
|
||||
const Point3f& pointModelJ = model.getSpinVertex(mj.modelInd);
|
||||
const Point3f& normalModelJ = model.getSpinNormal(mj.modelInd);
|
||||
|
||||
|
||||
gc = geometricConsistency(pointSceneI, normalSceneI, pointModelI, normalModelI,
|
||||
pointSceneJ, normalSceneJ, pointModelJ, normalModelJ);
|
||||
pointSceneJ, normalSceneJ, pointModelJ, normalModelJ);
|
||||
}
|
||||
|
||||
if (gc < model.T_GeometriccConsistency)
|
||||
++consistNum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (consistNum < matchesSize / 4) /* failed consistensy test */
|
||||
allMatches[i].measure = infinity;
|
||||
allMatches[i].measure = infinity;
|
||||
}
|
||||
allMatches.erase(
|
||||
remove_if(allMatches.begin(), allMatches.end(), bind2nd(equal_to<float>(), infinity)),
|
||||
allMatches.end());
|
||||
remove_if(allMatches.begin(), allMatches.end(), bind2nd(equal_to<float>(), infinity)),
|
||||
allMatches.end());
|
||||
if (out) *out << "Matches number [filtered by geometric consistency] = " << allMatches.size() << endl;
|
||||
|
||||
|
||||
@@ -1110,11 +1110,11 @@ private:
|
||||
if (out) *out << "grouping ..." << endl;
|
||||
|
||||
Mat groupingMat((int)matchesSize, (int)matchesSize, CV_32F);
|
||||
groupingMat = Scalar(0);
|
||||
|
||||
groupingMat = Scalar(0);
|
||||
|
||||
/* grouping */
|
||||
for(int j = 0; j < matchesSize; ++j)
|
||||
for(int i = j + 1; i < matchesSize; ++i)
|
||||
for(int i = j + 1; i < matchesSize; ++i)
|
||||
{
|
||||
const Match& mi = allMatches[i];
|
||||
const Match& mj = allMatches[j];
|
||||
@@ -1128,20 +1128,20 @@ private:
|
||||
|
||||
const Point3f& pointSceneI = scene.getSpinVertex(mi.sceneInd);
|
||||
const Point3f& normalSceneI = scene.getSpinNormal(mi.sceneInd);
|
||||
|
||||
|
||||
const Point3f& pointModelI = model.getSpinVertex(mi.modelInd);
|
||||
const Point3f& normalModelI = model.getSpinNormal(mi.modelInd);
|
||||
|
||||
|
||||
const Point3f& pointSceneJ = scene.getSpinVertex(mj.sceneInd);
|
||||
const Point3f& normalSceneJ = scene.getSpinNormal(mj.sceneInd);
|
||||
|
||||
|
||||
const Point3f& pointModelJ = model.getSpinVertex(mj.modelInd);
|
||||
const Point3f& normalModelJ = model.getSpinNormal(mj.modelInd);
|
||||
|
||||
float wgc = groupingCreteria(pointSceneI, normalSceneI, pointModelI, normalModelI,
|
||||
pointSceneJ, normalSceneJ, pointModelJ, normalModelJ,
|
||||
model.gamma);
|
||||
|
||||
model.gamma);
|
||||
|
||||
groupingMat.ptr<float>(i)[j] = wgc;
|
||||
groupingMat.ptr<float>(j)[i] = wgc;
|
||||
}
|
||||
@@ -1149,35 +1149,35 @@ private:
|
||||
group_t allMatchesInds;
|
||||
for(int i = 0; i < matchesSize; ++i)
|
||||
allMatchesInds.insert(i);
|
||||
|
||||
|
||||
vector<float> buf(matchesSize);
|
||||
float *buf_beg = &buf[0];
|
||||
vector<group_t> groups;
|
||||
|
||||
|
||||
for(int g = 0; g < matchesSize; ++g)
|
||||
{
|
||||
{
|
||||
if (out) if (g % 100 == 0) *out << "G = " << g << endl;
|
||||
|
||||
group_t left = allMatchesInds;
|
||||
group_t group;
|
||||
|
||||
|
||||
left.erase(g);
|
||||
group.insert(g);
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
size_t left_size = left.size();
|
||||
if (left_size == 0)
|
||||
break;
|
||||
|
||||
|
||||
std::transform(left.begin(), left.end(), buf_beg, WgcHelper(group, groupingMat));
|
||||
size_t minInd = min_element(buf_beg, buf_beg + left_size) - buf_beg;
|
||||
|
||||
|
||||
if (buf[minInd] < model.T_GroupingCorespondances) /* can add corespondance to group */
|
||||
{
|
||||
iter pos = left.begin();
|
||||
advance(pos, minInd);
|
||||
|
||||
|
||||
group.insert(*pos);
|
||||
left.erase(pos);
|
||||
}
|
||||
@@ -1199,16 +1199,16 @@ private:
|
||||
{
|
||||
const Match& m = allMatches[*pos];
|
||||
outgrp.push_back(Vec2i(subset[m.modelInd], scene.subset[m.sceneInd]));
|
||||
}
|
||||
}
|
||||
result.push_back(outgrp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cv::TickMeter::TickMeter() { reset(); }
|
||||
int64 cv::TickMeter::getTimeTicks() const { return sumTime; }
|
||||
double cv::TickMeter::getTimeMicro() const { return (double)getTimeTicks()/cvGetTickFrequency(); }
|
||||
double cv::TickMeter::getTimeMilli() const { return getTimeMicro()*1e-3; }
|
||||
double cv::TickMeter::getTimeSec() const { return getTimeMilli()*1e-3; }
|
||||
double cv::TickMeter::getTimeSec() const { return getTimeMilli()*1e-3; }
|
||||
int64 cv::TickMeter::getCounter() const { return counter; }
|
||||
void cv::TickMeter::reset() {startTime = 0; sumTime = 0; counter = 0; }
|
||||
|
||||
|
@@ -46,14 +46,14 @@
|
||||
Proceedings of the 5th International Symposium on Visual Computing, Vegas, USA
|
||||
|
||||
This code is written by Sergey G. Kosov for "Visir PX" application as part of Project X (www.project-10.de)
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include <limits.h>
|
||||
|
||||
namespace cv
|
||||
namespace cv
|
||||
{
|
||||
StereoVar::StereoVar() : levels(3), pyrScale(0.5), nIt(5), minDisp(0), maxDisp(16), poly_n(3), poly_sigma(0), fi(25.0f), lambda(0.03f), penalization(PENALIZATION_TICHONOV), cycle(CYCLE_V), flags(USE_SMART_ID | USE_AUTO_PARAMS)
|
||||
StereoVar::StereoVar() : levels(3), pyrScale(0.5), nIt(5), minDisp(0), maxDisp(16), poly_n(3), poly_sigma(0), fi(25.0f), lambda(0.03f), penalization(PENALIZATION_TICHONOV), cycle(CYCLE_V), flags(USE_SMART_ID | USE_AUTO_PARAMS)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ StereoVar::~StereoVar()
|
||||
|
||||
static Mat diffX(Mat &src)
|
||||
{
|
||||
register int x, y, cols = src.cols - 1;
|
||||
Mat dst(src.size(), src.type());
|
||||
for(y = 0; y < src.rows; y++){
|
||||
register int x, y, cols = src.cols - 1;
|
||||
Mat dst(src.size(), src.type());
|
||||
for(y = 0; y < src.rows; y++){
|
||||
const float* pSrc = src.ptr<float>(y);
|
||||
float* pDst = dst.ptr<float>(y);
|
||||
#if CV_SSE2
|
||||
@@ -92,319 +92,319 @@ static Mat diffX(Mat &src)
|
||||
|
||||
static Mat getGradient(Mat &src)
|
||||
{
|
||||
register int x, y;
|
||||
Mat dst(src.size(), src.type());
|
||||
dst.setTo(0);
|
||||
for (y = 0; y < src.rows - 1; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pSrcF = src.ptr<float>(y + 1);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (x = 0; x < src.cols - 1; x++)
|
||||
pDst[x] = fabs(pSrc[x + 1] - pSrc[x]) + fabs(pSrcF[x] - pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
register int x, y;
|
||||
Mat dst(src.size(), src.type());
|
||||
dst.setTo(0);
|
||||
for (y = 0; y < src.rows - 1; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pSrcF = src.ptr<float>(y + 1);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (x = 0; x < src.cols - 1; x++)
|
||||
pDst[x] = fabs(pSrc[x + 1] - pSrc[x]) + fabs(pSrcF[x] - pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static Mat getG_c(Mat &src, float l)
|
||||
{
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l / sqrtf(l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l / sqrtf(l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static Mat getG_p(Mat &src, float l)
|
||||
{
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l*l / (l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l*l / (l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void StereoVar::VariationalSolver(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level)
|
||||
{
|
||||
register int n, x, y;
|
||||
float gl = 1, gr = 1, gu = 1, gd = 1, gc = 4;
|
||||
Mat g_c, g_p;
|
||||
Mat U;
|
||||
u.copyTo(U);
|
||||
register int n, x, y;
|
||||
float gl = 1, gr = 1, gu = 1, gd = 1, gc = 4;
|
||||
Mat g_c, g_p;
|
||||
Mat U;
|
||||
u.copyTo(U);
|
||||
|
||||
int N = nIt;
|
||||
float l = lambda;
|
||||
float Fi = fi;
|
||||
int N = nIt;
|
||||
float l = lambda;
|
||||
float Fi = fi;
|
||||
|
||||
|
||||
if (flags & USE_SMART_ID) {
|
||||
double scale = pow(pyrScale, (double) level) * (1 + pyrScale);
|
||||
N = (int) (N / scale);
|
||||
}
|
||||
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
Fi /= (float) scale;
|
||||
l *= (float) scale;
|
||||
if (flags & USE_SMART_ID) {
|
||||
double scale = pow(pyrScale, (double) level) * (1 + pyrScale);
|
||||
N = (int) (N / scale);
|
||||
}
|
||||
|
||||
int width = u.cols - 1;
|
||||
int height = u.rows - 1;
|
||||
for (n = 0; n < N; n++) {
|
||||
if (penalization != PENALIZATION_TICHONOV) {
|
||||
Mat gradient = getGradient(U);
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER: g_c = getG_c(gradient, l); break;
|
||||
case PENALIZATION_PERONA_MALIK: g_p = getG_p(gradient, l); break;
|
||||
}
|
||||
gradient.release();
|
||||
}
|
||||
for (y = 1 ; y < height; y++) {
|
||||
float *pU = U.ptr<float>(y);
|
||||
float *pUu = U.ptr<float>(y + 1);
|
||||
float *pUd = U.ptr<float>(y - 1);
|
||||
float *pu = u.ptr<float>(y);
|
||||
float *pI1 = I1.ptr<float>(y);
|
||||
float *pI2 = I2.ptr<float>(y);
|
||||
float *pI2x = I2x.ptr<float>(y);
|
||||
float *pG_c = NULL, *pG_cu = NULL, *pG_cd = NULL;
|
||||
float *pG_p = NULL, *pG_pu = NULL, *pG_pd = NULL;
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
pG_c = g_c.ptr<float>(y);
|
||||
pG_cu = g_c.ptr<float>(y + 1);
|
||||
pG_cd = g_c.ptr<float>(y - 1);
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
pG_p = g_p.ptr<float>(y);
|
||||
pG_pu = g_p.ptr<float>(y + 1);
|
||||
pG_pd = g_p.ptr<float>(y - 1);
|
||||
break;
|
||||
}
|
||||
for (x = 1; x < width; x++) {
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
gc = pG_c[x];
|
||||
gl = gc + pG_c[x - 1];
|
||||
gr = gc + pG_c[x + 1];
|
||||
gu = gc + pG_cu[x];
|
||||
gd = gc + pG_cd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
gc = pG_p[x];
|
||||
gl = gc + pG_p[x - 1];
|
||||
gr = gc + pG_p[x + 1];
|
||||
gu = gc + pG_pu[x];
|
||||
gd = gc + pG_pd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
}
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
Fi /= (float) scale;
|
||||
l *= (float) scale;
|
||||
|
||||
float fi = Fi;
|
||||
if (maxDisp > minDisp) {
|
||||
if (pU[x] > maxDisp * scale) {fi *= 1000; pU[x] = static_cast<float>(maxDisp * scale);}
|
||||
if (pU[x] < minDisp * scale) {fi *= 1000; pU[x] = static_cast<float>(minDisp * scale);}
|
||||
}
|
||||
int width = u.cols - 1;
|
||||
int height = u.rows - 1;
|
||||
for (n = 0; n < N; n++) {
|
||||
if (penalization != PENALIZATION_TICHONOV) {
|
||||
Mat gradient = getGradient(U);
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER: g_c = getG_c(gradient, l); break;
|
||||
case PENALIZATION_PERONA_MALIK: g_p = getG_p(gradient, l); break;
|
||||
}
|
||||
gradient.release();
|
||||
}
|
||||
for (y = 1 ; y < height; y++) {
|
||||
float *pU = U.ptr<float>(y);
|
||||
float *pUu = U.ptr<float>(y + 1);
|
||||
float *pUd = U.ptr<float>(y - 1);
|
||||
float *pu = u.ptr<float>(y);
|
||||
float *pI1 = I1.ptr<float>(y);
|
||||
float *pI2 = I2.ptr<float>(y);
|
||||
float *pI2x = I2x.ptr<float>(y);
|
||||
float *pG_c = NULL, *pG_cu = NULL, *pG_cd = NULL;
|
||||
float *pG_p = NULL, *pG_pu = NULL, *pG_pd = NULL;
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
pG_c = g_c.ptr<float>(y);
|
||||
pG_cu = g_c.ptr<float>(y + 1);
|
||||
pG_cd = g_c.ptr<float>(y - 1);
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
pG_p = g_p.ptr<float>(y);
|
||||
pG_pu = g_p.ptr<float>(y + 1);
|
||||
pG_pd = g_p.ptr<float>(y - 1);
|
||||
break;
|
||||
}
|
||||
for (x = 1; x < width; x++) {
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
gc = pG_c[x];
|
||||
gl = gc + pG_c[x - 1];
|
||||
gr = gc + pG_c[x + 1];
|
||||
gu = gc + pG_cu[x];
|
||||
gd = gc + pG_cd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
gc = pG_p[x];
|
||||
gl = gc + pG_p[x - 1];
|
||||
gr = gc + pG_p[x + 1];
|
||||
gu = gc + pG_pu[x];
|
||||
gd = gc + pG_pd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
}
|
||||
|
||||
int A = static_cast<int>(pU[x]);
|
||||
int neg = 0; if (pU[x] <= 0) neg = -1;
|
||||
float _fi = Fi;
|
||||
if (maxDisp > minDisp) {
|
||||
if (pU[x] > maxDisp * scale) {_fi *= 1000; pU[x] = static_cast<float>(maxDisp * scale);}
|
||||
if (pU[x] < minDisp * scale) {_fi *= 1000; pU[x] = static_cast<float>(minDisp * scale);}
|
||||
}
|
||||
|
||||
if (x + A > width)
|
||||
pu[x] = pU[width - A];
|
||||
else if (x + A + neg < 0)
|
||||
pu[x] = pU[- A + 2];
|
||||
else {
|
||||
pu[x] = A + (pI2x[x + A + neg] * (pI1[x] - pI2[x + A])
|
||||
+ fi * (gr * pU[x + 1] + gl * pU[x - 1] + gu * pUu[x] + gd * pUd[x] - gc * A))
|
||||
/ (pI2x[x + A + neg] * pI2x[x + A + neg] + gc * fi) ;
|
||||
}
|
||||
}// x
|
||||
pu[0] = pu[1];
|
||||
pu[width] = pu[width - 1];
|
||||
}// y
|
||||
for (x = 0; x <= width; x++) {
|
||||
u.at<float>(0, x) = u.at<float>(1, x);
|
||||
u.at<float>(height, x) = u.at<float>(height - 1, x);
|
||||
}
|
||||
u.copyTo(U);
|
||||
if (!g_c.empty()) g_c.release();
|
||||
if (!g_p.empty()) g_p.release();
|
||||
}//n
|
||||
int A = static_cast<int>(pU[x]);
|
||||
int neg = 0; if (pU[x] <= 0) neg = -1;
|
||||
|
||||
if (x + A > width)
|
||||
pu[x] = pU[width - A];
|
||||
else if (x + A + neg < 0)
|
||||
pu[x] = pU[- A + 2];
|
||||
else {
|
||||
pu[x] = A + (pI2x[x + A + neg] * (pI1[x] - pI2[x + A])
|
||||
+ _fi * (gr * pU[x + 1] + gl * pU[x - 1] + gu * pUu[x] + gd * pUd[x] - gc * A))
|
||||
/ (pI2x[x + A + neg] * pI2x[x + A + neg] + gc * _fi) ;
|
||||
}
|
||||
}// x
|
||||
pu[0] = pu[1];
|
||||
pu[width] = pu[width - 1];
|
||||
}// y
|
||||
for (x = 0; x <= width; x++) {
|
||||
u.at<float>(0, x) = u.at<float>(1, x);
|
||||
u.at<float>(height, x) = u.at<float>(height - 1, x);
|
||||
}
|
||||
u.copyTo(U);
|
||||
if (!g_c.empty()) g_c.release();
|
||||
if (!g_p.empty()) g_p.release();
|
||||
}//n
|
||||
}
|
||||
|
||||
void StereoVar::VCycle_MyFAS(Mat &I1, Mat &I2, Mat &I2x, Mat &_u, int level)
|
||||
{
|
||||
CvSize imgSize = _u.size();
|
||||
CvSize frmSize = cvSize((int) (imgSize.width * pyrScale + 0.5), (int) (imgSize.height * pyrScale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h, U, U_h;
|
||||
CvSize imgSize = _u.size();
|
||||
CvSize frmSize = cvSize((int) (imgSize.width * pyrScale + 0.5), (int) (imgSize.height * pyrScale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h, U, U_h;
|
||||
|
||||
//PRE relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level);
|
||||
//PRE relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level);
|
||||
|
||||
if (level >= levels - 1) return;
|
||||
level ++;
|
||||
if (level >= levels - 1) return;
|
||||
level ++;
|
||||
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(_u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), pyrScale);
|
||||
I2x_h = diffX(I2_h);
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(_u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), pyrScale);
|
||||
I2x_h = diffX(I2_h);
|
||||
|
||||
//Next level
|
||||
U_h = u_h.clone();
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, U_h, level);
|
||||
//Next level
|
||||
U_h = u_h.clone();
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, U_h, level);
|
||||
|
||||
subtract(U_h, u_h, U_h);
|
||||
U_h.convertTo(U_h, U_h.type(), 1.0 / pyrScale);
|
||||
subtract(U_h, u_h, U_h);
|
||||
U_h.convertTo(U_h, U_h.type(), 1.0 / pyrScale);
|
||||
|
||||
//scaling UP
|
||||
resize(U_h, U, imgSize);
|
||||
//scaling UP
|
||||
resize(U_h, U, imgSize);
|
||||
|
||||
//correcting the solution
|
||||
add(_u, U, _u);
|
||||
//correcting the solution
|
||||
add(_u, U, _u);
|
||||
|
||||
//POST relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level - 1);
|
||||
//POST relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level - 1);
|
||||
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(_u, _u, 3);
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(_u, _u, 3);
|
||||
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
U.release();
|
||||
U_h.release();
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
U.release();
|
||||
U_h.release();
|
||||
}
|
||||
|
||||
void StereoVar::FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level)
|
||||
{
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
CvSize frmSize = cvSize((int) (u.cols * scale + 0.5), (int) (u.rows * scale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h;
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
CvSize frmSize = cvSize((int) (u.cols * scale + 0.5), (int) (u.rows * scale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h;
|
||||
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), scale);
|
||||
I2x_h = diffX(I2_h);
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), scale);
|
||||
I2x_h = diffX(I2_h);
|
||||
|
||||
switch (cycle) {
|
||||
case CYCLE_O:
|
||||
VariationalSolver(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
case CYCLE_V:
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
}
|
||||
switch (cycle) {
|
||||
case CYCLE_O:
|
||||
VariationalSolver(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
case CYCLE_V:
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
}
|
||||
|
||||
u_h.convertTo(u_h, u_h.type(), 1.0 / scale);
|
||||
u_h.convertTo(u_h, u_h.type(), 1.0 / scale);
|
||||
|
||||
//scaling UP
|
||||
resize(u_h, u, u.size(), 0, 0, INTER_CUBIC);
|
||||
//scaling UP
|
||||
resize(u_h, u, u.size(), 0, 0, INTER_CUBIC);
|
||||
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
|
||||
level--;
|
||||
if ((flags & USE_AUTO_PARAMS) && (level < levels / 3)) {
|
||||
penalization = PENALIZATION_PERONA_MALIK;
|
||||
fi *= 100;
|
||||
flags -= USE_AUTO_PARAMS;
|
||||
autoParams();
|
||||
}
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(u, u, 3);
|
||||
if (level >= 0) FMG(I1, I2, I2x, u, level);
|
||||
level--;
|
||||
if ((flags & USE_AUTO_PARAMS) && (level < levels / 3)) {
|
||||
penalization = PENALIZATION_PERONA_MALIK;
|
||||
fi *= 100;
|
||||
flags -= USE_AUTO_PARAMS;
|
||||
autoParams();
|
||||
}
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(u, u, 3);
|
||||
if (level >= 0) FMG(I1, I2, I2x, u, level);
|
||||
}
|
||||
|
||||
void StereoVar::autoParams()
|
||||
{
|
||||
int maxD = MAX(labs(maxDisp), labs(minDisp));
|
||||
|
||||
if (!maxD) pyrScale = 0.85;
|
||||
else if (maxD < 8) pyrScale = 0.5;
|
||||
else if (maxD < 64) pyrScale = 0.5 + static_cast<double>(maxD - 8) * 0.00625;
|
||||
else pyrScale = 0.85;
|
||||
|
||||
if (maxD) {
|
||||
levels = 0;
|
||||
while ( pow(pyrScale, levels) * maxD > 1.5) levels ++;
|
||||
levels++;
|
||||
}
|
||||
{
|
||||
int maxD = MAX(labs(maxDisp), labs(minDisp));
|
||||
|
||||
switch(penalization) {
|
||||
case PENALIZATION_TICHONOV: cycle = CYCLE_V; break;
|
||||
case PENALIZATION_CHARBONNIER: cycle = CYCLE_O; break;
|
||||
case PENALIZATION_PERONA_MALIK: cycle = CYCLE_O; break;
|
||||
}
|
||||
if (!maxD) pyrScale = 0.85;
|
||||
else if (maxD < 8) pyrScale = 0.5;
|
||||
else if (maxD < 64) pyrScale = 0.5 + static_cast<double>(maxD - 8) * 0.00625;
|
||||
else pyrScale = 0.85;
|
||||
|
||||
if (maxD) {
|
||||
levels = 0;
|
||||
while ( pow(pyrScale, levels) * maxD > 1.5) levels ++;
|
||||
levels++;
|
||||
}
|
||||
|
||||
switch(penalization) {
|
||||
case PENALIZATION_TICHONOV: cycle = CYCLE_V; break;
|
||||
case PENALIZATION_CHARBONNIER: cycle = CYCLE_O; break;
|
||||
case PENALIZATION_PERONA_MALIK: cycle = CYCLE_O; break;
|
||||
}
|
||||
}
|
||||
|
||||
void StereoVar::operator ()( const Mat& left, const Mat& right, Mat& disp )
|
||||
{
|
||||
CV_Assert(left.size() == right.size() && left.type() == right.type());
|
||||
CvSize imgSize = left.size();
|
||||
int MaxD = MAX(labs(minDisp), labs(maxDisp));
|
||||
int SignD = 1; if (MIN(minDisp, maxDisp) < 0) SignD = -1;
|
||||
if (minDisp >= maxDisp) {MaxD = 256; SignD = 1;}
|
||||
|
||||
Mat u;
|
||||
if ((flags & USE_INITIAL_DISPARITY) && (!disp.empty())) {
|
||||
CV_Assert(disp.size() == left.size() && disp.type() == CV_8UC1);
|
||||
disp.convertTo(u, CV_32FC1, static_cast<double>(SignD * MaxD) / 256);
|
||||
} else {
|
||||
u.create(imgSize, CV_32FC1);
|
||||
u.setTo(0);
|
||||
}
|
||||
CV_Assert(left.size() == right.size() && left.type() == right.type());
|
||||
CvSize imgSize = left.size();
|
||||
int MaxD = MAX(labs(minDisp), labs(maxDisp));
|
||||
int SignD = 1; if (MIN(minDisp, maxDisp) < 0) SignD = -1;
|
||||
if (minDisp >= maxDisp) {MaxD = 256; SignD = 1;}
|
||||
|
||||
// Preprocessing
|
||||
Mat leftgray, rightgray;
|
||||
if (left.type() != CV_8UC1) {
|
||||
cvtColor(left, leftgray, CV_BGR2GRAY);
|
||||
cvtColor(right, rightgray, CV_BGR2GRAY);
|
||||
} else {
|
||||
left.copyTo(leftgray);
|
||||
right.copyTo(rightgray);
|
||||
}
|
||||
if (flags & USE_EQUALIZE_HIST) {
|
||||
equalizeHist(leftgray, leftgray);
|
||||
equalizeHist(rightgray, rightgray);
|
||||
}
|
||||
if (poly_sigma > 0.0001) {
|
||||
GaussianBlur(leftgray, leftgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
GaussianBlur(rightgray, rightgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
}
|
||||
|
||||
if (flags & USE_AUTO_PARAMS) {
|
||||
penalization = PENALIZATION_TICHONOV;
|
||||
autoParams();
|
||||
}
|
||||
Mat u;
|
||||
if ((flags & USE_INITIAL_DISPARITY) && (!disp.empty())) {
|
||||
CV_Assert(disp.size() == left.size() && disp.type() == CV_8UC1);
|
||||
disp.convertTo(u, CV_32FC1, static_cast<double>(SignD * MaxD) / 256);
|
||||
} else {
|
||||
u.create(imgSize, CV_32FC1);
|
||||
u.setTo(0);
|
||||
}
|
||||
|
||||
Mat I1, I2;
|
||||
leftgray.convertTo(I1, CV_32FC1);
|
||||
rightgray.convertTo(I2, CV_32FC1);
|
||||
leftgray.release();
|
||||
rightgray.release();
|
||||
// Preprocessing
|
||||
Mat leftgray, rightgray;
|
||||
if (left.type() != CV_8UC1) {
|
||||
cvtColor(left, leftgray, CV_BGR2GRAY);
|
||||
cvtColor(right, rightgray, CV_BGR2GRAY);
|
||||
} else {
|
||||
left.copyTo(leftgray);
|
||||
right.copyTo(rightgray);
|
||||
}
|
||||
if (flags & USE_EQUALIZE_HIST) {
|
||||
equalizeHist(leftgray, leftgray);
|
||||
equalizeHist(rightgray, rightgray);
|
||||
}
|
||||
if (poly_sigma > 0.0001) {
|
||||
GaussianBlur(leftgray, leftgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
GaussianBlur(rightgray, rightgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
}
|
||||
|
||||
Mat I2x = diffX(I2);
|
||||
|
||||
FMG(I1, I2, I2x, u, levels - 1);
|
||||
|
||||
I1.release();
|
||||
I2.release();
|
||||
I2x.release();
|
||||
|
||||
|
||||
disp.create( left.size(), CV_8UC1 );
|
||||
u = abs(u);
|
||||
u.convertTo(disp, disp.type(), 256 / MaxD, 0);
|
||||
if (flags & USE_AUTO_PARAMS) {
|
||||
penalization = PENALIZATION_TICHONOV;
|
||||
autoParams();
|
||||
}
|
||||
|
||||
u.release();
|
||||
Mat I1, I2;
|
||||
leftgray.convertTo(I1, CV_32FC1);
|
||||
rightgray.convertTo(I2, CV_32FC1);
|
||||
leftgray.release();
|
||||
rightgray.release();
|
||||
|
||||
Mat I2x = diffX(I2);
|
||||
|
||||
FMG(I1, I2, I2x, u, levels - 1);
|
||||
|
||||
I1.release();
|
||||
I2.release();
|
||||
I2x.release();
|
||||
|
||||
|
||||
disp.create( left.size(), CV_8UC1 );
|
||||
u = abs(u);
|
||||
u.convertTo(disp, disp.type(), 256 / MaxD, 0);
|
||||
|
||||
u.release();
|
||||
}
|
||||
} // namespace
|
Reference in New Issue
Block a user