Permalink
Browse files

fix bug in KLT_response

  • Loading branch information...
jlblancoc committed Dec 28, 2018
1 parent 8c05e8f commit 6a555a385201d8e7145f97302595182931aa6837
Showing with 8 additions and 6 deletions.
  1. +5 −4 libs/img/src/CImage.cpp
  2. +3 −2 libs/img/src/CImage_unittest.cpp
@@ -1797,10 +1797,11 @@ void image_KLT_response_template(
{
const uint8_t* ptr = in + widthStep * yy + min_x;
unsigned int xx = min_x;
for (unsigned int ix = WIN_SIZE; ix; --ix, ++xx)
for (unsigned int ix = WIN_SIZE; ix; --ix, ++xx,++ptr)
{
const int32_t dx = ptr[+1] - ptr[-1];
const int32_t dy = ptr[+widthStep] - ptr[-widthStep];
const int32_t dx = static_cast<int32_t>(ptr[+1]) - static_cast<int32_t>(ptr[-1]);
const int32_t dy = static_cast<int32_t>(ptr[+widthStep]) -
static_cast<int32_t>(ptr[-widthStep]);
gxx += dx * dx;
gxy += dx * dy;
gyy += dy * dy;
@@ -1820,7 +1821,7 @@ float CImage::KLT_response(
const auto& im1 = m_impl->img;
const auto img_w = static_cast<unsigned int>(im1.cols),
img_h = static_cast<unsigned int>(im1.rows);
const auto widthStep = im1.step[0];
const int widthStep = im1.step[0];

// If any of those predefined values worked, do the generic way:
const unsigned int min_x = x - half_window_size;
@@ -382,12 +382,13 @@ TEST(CImage, KLT_response)
{
CImage a(100, 90, CH_GRAY);
a.filledRectangle(0, 0, 99, 99, TColor(0x10));
a.filledRectangle(40, 30, 41, 31, TColor(0xf0));
a.filledRectangle(40, 30, 41, 31, TColor(0x20));
a.saveToFile("a.png");

for (int w = 2; w < 12; w++)
{
const auto resp = a.KLT_response(40, 30, w);
// std::cout << "JLT [w=" << w << "]=" << resp << "\n";
EXPECT_GT(resp, 0.5f);
}
}
}

0 comments on commit 6a555a3

Please sign in to comment.