Skip to content

Commit

Permalink
Fixed Initialization bug, reduced possible allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyi committed Jun 18, 2015
1 parent 3ffa391 commit c8dd272
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions c++/Lib/src/libTILDE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class Parallel_process:public cv::ParallelLoopBody {
Mat res;
sepFilter2D(convt_image[idxDim], res, -1, kernelX, kernelY, Point(-1, -1),
0, BORDER_REFLECT);
curRes[idxFilter] = res.clone();
curRes[idxFilter] = res.clone(); // not cloning causes wierd issues.

}}};

Expand Down Expand Up @@ -676,7 +676,7 @@ void getScoresandCombine_Approx(const TILDEobjects & cas,

*output = Mat::zeros(convt_image[0].size(), CV_32F);

vector < vector < Mat > >res(nbSum,vector < Mat >(nbMax));
vector < vector < Mat > >res(nbSum,vector < Mat >(nbMax, Mat::zeros(convt_image[0].size(), CV_32F)));

// calculate separable responses
int idxSum = 0;
Expand All @@ -690,17 +690,18 @@ void getScoresandCombine_Approx(const TILDEobjects & cas,

Mat maxVal;
int count = 0;
for (int idxOrig = 0; idxOrig < nbSum * nbMax; ++idxOrig)
for (int idxOrig = 0; idxOrig < nbSum * nbMax; ++idxOrig)
{
int idxSum = idxOrig / nbMax;
int idxMax = idxOrig % nbMax;

Mat result = res[idxSum][idxMax];

for (int idxFilter = 0; idxFilter < cas.filters.size() / 2; idxFilter++)
result = result + cas.coeffs[idxOrig][idxFilter] * curRes[idxFilter];
// Mat result = res[idxSum][idxMax];
for (int idxFilter = 0; idxFilter < cas.filters.size() / 2; idxFilter++)
cv::scaleAdd(curRes[idxFilter], cas.coeffs[idxOrig][idxFilter], res[idxSum][idxMax], res[idxSum][idxMax]);
// result = result + cas.coeffs[idxOrig][idxFilter] * curRes[idxFilter];

res[idxSum][idxMax] = result + cas.bias[idxMax + idxSum*nbMax];
cv::add(res[idxSum][idxMax], cas.bias[idxMax + idxSum*nbMax], res[idxSum][idxMax]);
// res[idxSum][idxMax] = result + cas.bias[idxMax + idxSum*nbMax];

if (idxOrig % nbMax == 0)
maxVal = res[idxSum][idxMax];
Expand All @@ -709,8 +710,10 @@ void getScoresandCombine_Approx(const TILDEobjects & cas,

if ((idxOrig+1) % nbMax == 0)//the last one
{
// sign and sum
*output = (idxSum % 2 == 0 ? -maxVal : maxVal) + *output;
// // sign and sum
// *output = (idxSum % 2 == 0 ? -maxVal : maxVal) + *output;
float sign_delta = (idxSum % 2 == 0 ? -1. : 1.);
cv::scaleAdd(maxVal, sign_delta, *output, *output);
}
}

Expand Down

0 comments on commit c8dd272

Please sign in to comment.