Skip to content

Commit 6847cc9

Browse files
committed
akaze: remove usage of int8_t / uint8_t
1 parent 411d36f commit 6847cc9

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,12 +1205,11 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
12051205
{ 0.00344629f, 0.00318132f, 0.00250252f, 0.00167749f, 0.00095820f, 0.00046640f, 0.00019346f },
12061206
{ 0.00142946f, 0.00131956f, 0.00103800f, 0.00069579f, 0.00039744f, 0.00019346f, 0.00008024f }
12071207
};
1208-
static const int id[] = { 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6 };
12091208
static const struct gtable
12101209
{
12111210
float weight[109];
1212-
int8_t xidx[109];
1213-
int8_t yidx[109];
1211+
int xidx[109];
1212+
int yidx[109];
12141213

12151214
explicit gtable(void)
12161215
{
@@ -1219,29 +1218,28 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
12191218
for (int i = -6; i <= 6; ++i) {
12201219
for (int j = -6; j <= 6; ++j) {
12211220
if (i*i + j*j < 36) {
1222-
weight[k] = gauss25[id[i + 6]][id[j + 6]];
1223-
yidx[k] = static_cast<int8_t>(i);
1224-
xidx[k] = static_cast<int8_t>(j);
1221+
CV_Assert(k < 109);
1222+
weight[k] = gauss25[abs(i)][abs(j)];
1223+
yidx[k] = i;
1224+
xidx[k] = j;
12251225
++k;
12261226
}
12271227
}
12281228
}
1229-
CV_DbgAssert(k == 109);
12301229
}
12311230
} g;
12321231

1233-
const float * lx = Lx.ptr<float>(0);
1234-
const float * ly = Ly.ptr<float>(0);
1235-
int cols = Lx.cols;
1232+
CV_Assert(x0 - 6 * scale >= 0 && x0 + 6 * scale < Lx.cols);
1233+
CV_Assert(y0 - 6 * scale >= 0 && y0 + 6 * scale < Lx.rows);
12361234

1237-
for (int i = 0; i < 109; i++) {
1238-
int j = (y0 + g.yidx[i] * scale) * cols + (x0 + g.xidx[i] * scale);
1239-
1240-
resX[i] = g.weight[i] * lx[j];
1241-
resY[i] = g.weight[i] * ly[j];
1235+
for (int i = 0; i < 109; i++)
1236+
{
1237+
int y = y0 + g.yidx[i] * scale;
1238+
int x = x0 + g.xidx[i] * scale;
12421239

1243-
CV_DbgAssert(isfinite(resX[i]));
1244-
CV_DbgAssert(isfinite(resY[i]));
1240+
float w = g.weight[i];
1241+
resX[i] = w * Lx.at<float>(y, x);
1242+
resY[i] = w * Ly.at<float>(y, x);
12451243
}
12461244
}
12471245

@@ -1250,7 +1248,7 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
12501248
* @param a[] Input floating point array to sort
12511249
* @param n The length of a[]
12521250
* @param quantum The interval to convert a[i]'s float values to integers
1253-
* @param max The upper bound of a[], meaning a[i] must be in [0, max]
1251+
* @param nkeys a[i] < nkeys * quantum
12541252
* @param idx[] Output array of the indices: a[idx[i]] forms a sorted array
12551253
* @param cum[] Output array of the starting indices of quantized floats
12561254
* @note The values of a[] in [k*quantum, (k + 1)*quantum) is labeled by
@@ -1260,25 +1258,35 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
12601258
*/
12611259
static inline
12621260
void quantized_counting_sort(const float a[], const int n,
1263-
const float quantum, const float max,
1264-
uint8_t idx[], uint8_t cum[])
1261+
const float quantum, const int nkeys,
1262+
int idx[/*n*/], int cum[/*nkeys + 1*/])
12651263
{
1266-
const int nkeys = (int)(max / quantum);
1267-
1268-
// The size of cum[] must be nkeys + 1
1269-
memset(cum, 0, nkeys + 1);
1264+
memset(cum, 0, sizeof(cum[0]) * (nkeys + 1));
12701265

12711266
// Count up the quantized values
12721267
for (int i = 0; i < n; i++)
1273-
cum[(int)(a[i] / quantum)]++;
1268+
{
1269+
int b = (int)(a[i] / quantum);
1270+
if (b < 0 || b >= nkeys)
1271+
b = 0;
1272+
cum[b]++;
1273+
}
12741274

12751275
// Compute the inclusive prefix sum i.e. the end indices; cum[nkeys] is the total
12761276
for (int i = 1; i <= nkeys; i++)
1277+
{
12771278
cum[i] += cum[i - 1];
1279+
}
1280+
CV_Assert(cum[nkeys] == n);
12781281

12791282
// Generate the sorted indices; cum[] becomes the exclusive prefix sum i.e. the start indices of keys
12801283
for (int i = 0; i < n; i++)
1281-
idx[--cum[(int)(a[i] / quantum)]] = static_cast<uint8_t>(i);
1284+
{
1285+
int b = (int)(a[i] / quantum);
1286+
if (b < 0 || b >= nkeys)
1287+
b = 0;
1288+
idx[--cum[b]] = i;
1289+
}
12821290
}
12831291

12841292
/**
@@ -1309,17 +1317,18 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
13091317
// Sort by the angles; angles are labeled by slices of 0.15 radian
13101318
const int slices = 42;
13111319
const float ang_step = (float)(2.0 * CV_PI / slices);
1312-
uint8_t slice[slices + 1];
1313-
uint8_t sorted_idx[ang_size];
1314-
quantized_counting_sort(Ang, ang_size, ang_step, (float)(2.0 * CV_PI), sorted_idx, slice);
1320+
int slice[slices + 1];
1321+
int sorted_idx[ang_size];
1322+
quantized_counting_sort(Ang, ang_size, ang_step, slices, sorted_idx, slice);
13151323

13161324
// Find the main angle by sliding a window of 7-slice size(=PI/3) around the keypoint
13171325
const int win = 7;
13181326

13191327
float maxX = 0.0f, maxY = 0.0f;
13201328
for (int i = slice[0]; i < slice[win]; i++) {
1321-
maxX += resX[sorted_idx[i]];
1322-
maxY += resY[sorted_idx[i]];
1329+
const int idx = sorted_idx[i];
1330+
maxX += resX[idx];
1331+
maxY += resY[idx];
13231332
}
13241333
float maxNorm = maxX * maxX + maxY * maxY;
13251334

@@ -1330,8 +1339,9 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
13301339

13311340
float sumX = 0.0f, sumY = 0.0f;
13321341
for (int i = slice[sn]; i < slice[sn + win]; i++) {
1333-
sumX += resX[sorted_idx[i]];
1334-
sumY += resY[sorted_idx[i]];
1342+
const int idx = sorted_idx[i];
1343+
sumX += resX[idx];
1344+
sumY += resY[idx];
13351345
}
13361346

13371347
float norm = sumX * sumX + sumY * sumY;
@@ -1347,12 +1357,14 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
13471357

13481358
float sumX = 0.0f, sumY = 0.0f;
13491359
for (int i = slice[sn]; i < slice[slices]; i++) {
1350-
sumX += resX[sorted_idx[i]];
1351-
sumY += resY[sorted_idx[i]];
1360+
const int idx = sorted_idx[i];
1361+
sumX += resX[idx];
1362+
sumY += resY[idx];
13521363
}
13531364
for (int i = slice[0]; i < slice[remain]; i++) {
1354-
sumX += resX[sorted_idx[i]];
1355-
sumY += resY[sorted_idx[i]];
1365+
const int idx = sorted_idx[i];
1366+
sumX += resX[idx];
1367+
sumY += resY[idx];
13561368
}
13571369

13581370
float norm = sumX * sumX + sumY * sumY;

0 commit comments

Comments
 (0)