mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 04:52:53 +08:00
akaze: remove usage of int8_t / uint8_t
This commit is contained in:
parent
411d36ff13
commit
6847cc9f1c
@ -1205,12 +1205,11 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
|
|||||||
{ 0.00344629f, 0.00318132f, 0.00250252f, 0.00167749f, 0.00095820f, 0.00046640f, 0.00019346f },
|
{ 0.00344629f, 0.00318132f, 0.00250252f, 0.00167749f, 0.00095820f, 0.00046640f, 0.00019346f },
|
||||||
{ 0.00142946f, 0.00131956f, 0.00103800f, 0.00069579f, 0.00039744f, 0.00019346f, 0.00008024f }
|
{ 0.00142946f, 0.00131956f, 0.00103800f, 0.00069579f, 0.00039744f, 0.00019346f, 0.00008024f }
|
||||||
};
|
};
|
||||||
static const int id[] = { 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6 };
|
|
||||||
static const struct gtable
|
static const struct gtable
|
||||||
{
|
{
|
||||||
float weight[109];
|
float weight[109];
|
||||||
int8_t xidx[109];
|
int xidx[109];
|
||||||
int8_t yidx[109];
|
int yidx[109];
|
||||||
|
|
||||||
explicit gtable(void)
|
explicit gtable(void)
|
||||||
{
|
{
|
||||||
@ -1219,29 +1218,28 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
|
|||||||
for (int i = -6; i <= 6; ++i) {
|
for (int i = -6; i <= 6; ++i) {
|
||||||
for (int j = -6; j <= 6; ++j) {
|
for (int j = -6; j <= 6; ++j) {
|
||||||
if (i*i + j*j < 36) {
|
if (i*i + j*j < 36) {
|
||||||
weight[k] = gauss25[id[i + 6]][id[j + 6]];
|
CV_Assert(k < 109);
|
||||||
yidx[k] = static_cast<int8_t>(i);
|
weight[k] = gauss25[abs(i)][abs(j)];
|
||||||
xidx[k] = static_cast<int8_t>(j);
|
yidx[k] = i;
|
||||||
|
xidx[k] = j;
|
||||||
++k;
|
++k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CV_DbgAssert(k == 109);
|
|
||||||
}
|
}
|
||||||
} g;
|
} g;
|
||||||
|
|
||||||
const float * lx = Lx.ptr<float>(0);
|
CV_Assert(x0 - 6 * scale >= 0 && x0 + 6 * scale < Lx.cols);
|
||||||
const float * ly = Ly.ptr<float>(0);
|
CV_Assert(y0 - 6 * scale >= 0 && y0 + 6 * scale < Lx.rows);
|
||||||
int cols = Lx.cols;
|
|
||||||
|
|
||||||
for (int i = 0; i < 109; i++) {
|
for (int i = 0; i < 109; i++)
|
||||||
int j = (y0 + g.yidx[i] * scale) * cols + (x0 + g.xidx[i] * scale);
|
{
|
||||||
|
int y = y0 + g.yidx[i] * scale;
|
||||||
|
int x = x0 + g.xidx[i] * scale;
|
||||||
|
|
||||||
resX[i] = g.weight[i] * lx[j];
|
float w = g.weight[i];
|
||||||
resY[i] = g.weight[i] * ly[j];
|
resX[i] = w * Lx.at<float>(y, x);
|
||||||
|
resY[i] = w * Ly.at<float>(y, x);
|
||||||
CV_DbgAssert(isfinite(resX[i]));
|
|
||||||
CV_DbgAssert(isfinite(resY[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1250,7 +1248,7 @@ void Sample_Derivative_Response_Radius6(const Mat &Lx, const Mat &Ly,
|
|||||||
* @param a[] Input floating point array to sort
|
* @param a[] Input floating point array to sort
|
||||||
* @param n The length of a[]
|
* @param n The length of a[]
|
||||||
* @param quantum The interval to convert a[i]'s float values to integers
|
* @param quantum The interval to convert a[i]'s float values to integers
|
||||||
* @param max The upper bound of a[], meaning a[i] must be in [0, max]
|
* @param nkeys a[i] < nkeys * quantum
|
||||||
* @param idx[] Output array of the indices: a[idx[i]] forms a sorted array
|
* @param idx[] Output array of the indices: a[idx[i]] forms a sorted array
|
||||||
* @param cum[] Output array of the starting indices of quantized floats
|
* @param cum[] Output array of the starting indices of quantized floats
|
||||||
* @note The values of a[] in [k*quantum, (k + 1)*quantum) is labeled by
|
* @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,
|
|||||||
*/
|
*/
|
||||||
static inline
|
static inline
|
||||||
void quantized_counting_sort(const float a[], const int n,
|
void quantized_counting_sort(const float a[], const int n,
|
||||||
const float quantum, const float max,
|
const float quantum, const int nkeys,
|
||||||
uint8_t idx[], uint8_t cum[])
|
int idx[/*n*/], int cum[/*nkeys + 1*/])
|
||||||
{
|
{
|
||||||
const int nkeys = (int)(max / quantum);
|
memset(cum, 0, sizeof(cum[0]) * (nkeys + 1));
|
||||||
|
|
||||||
// The size of cum[] must be nkeys + 1
|
|
||||||
memset(cum, 0, nkeys + 1);
|
|
||||||
|
|
||||||
// Count up the quantized values
|
// Count up the quantized values
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
cum[(int)(a[i] / quantum)]++;
|
{
|
||||||
|
int b = (int)(a[i] / quantum);
|
||||||
|
if (b < 0 || b >= nkeys)
|
||||||
|
b = 0;
|
||||||
|
cum[b]++;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the inclusive prefix sum i.e. the end indices; cum[nkeys] is the total
|
// Compute the inclusive prefix sum i.e. the end indices; cum[nkeys] is the total
|
||||||
for (int i = 1; i <= nkeys; i++)
|
for (int i = 1; i <= nkeys; i++)
|
||||||
|
{
|
||||||
cum[i] += cum[i - 1];
|
cum[i] += cum[i - 1];
|
||||||
|
}
|
||||||
|
CV_Assert(cum[nkeys] == n);
|
||||||
|
|
||||||
// Generate the sorted indices; cum[] becomes the exclusive prefix sum i.e. the start indices of keys
|
// Generate the sorted indices; cum[] becomes the exclusive prefix sum i.e. the start indices of keys
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
idx[--cum[(int)(a[i] / quantum)]] = static_cast<uint8_t>(i);
|
{
|
||||||
|
int b = (int)(a[i] / quantum);
|
||||||
|
if (b < 0 || b >= nkeys)
|
||||||
|
b = 0;
|
||||||
|
idx[--cum[b]] = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1309,17 +1317,18 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
|
|||||||
// Sort by the angles; angles are labeled by slices of 0.15 radian
|
// Sort by the angles; angles are labeled by slices of 0.15 radian
|
||||||
const int slices = 42;
|
const int slices = 42;
|
||||||
const float ang_step = (float)(2.0 * CV_PI / slices);
|
const float ang_step = (float)(2.0 * CV_PI / slices);
|
||||||
uint8_t slice[slices + 1];
|
int slice[slices + 1];
|
||||||
uint8_t sorted_idx[ang_size];
|
int sorted_idx[ang_size];
|
||||||
quantized_counting_sort(Ang, ang_size, ang_step, (float)(2.0 * CV_PI), sorted_idx, slice);
|
quantized_counting_sort(Ang, ang_size, ang_step, slices, sorted_idx, slice);
|
||||||
|
|
||||||
// Find the main angle by sliding a window of 7-slice size(=PI/3) around the keypoint
|
// Find the main angle by sliding a window of 7-slice size(=PI/3) around the keypoint
|
||||||
const int win = 7;
|
const int win = 7;
|
||||||
|
|
||||||
float maxX = 0.0f, maxY = 0.0f;
|
float maxX = 0.0f, maxY = 0.0f;
|
||||||
for (int i = slice[0]; i < slice[win]; i++) {
|
for (int i = slice[0]; i < slice[win]; i++) {
|
||||||
maxX += resX[sorted_idx[i]];
|
const int idx = sorted_idx[i];
|
||||||
maxY += resY[sorted_idx[i]];
|
maxX += resX[idx];
|
||||||
|
maxY += resY[idx];
|
||||||
}
|
}
|
||||||
float maxNorm = maxX * maxX + maxY * maxY;
|
float maxNorm = maxX * maxX + maxY * maxY;
|
||||||
|
|
||||||
@ -1330,8 +1339,9 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
|
|||||||
|
|
||||||
float sumX = 0.0f, sumY = 0.0f;
|
float sumX = 0.0f, sumY = 0.0f;
|
||||||
for (int i = slice[sn]; i < slice[sn + win]; i++) {
|
for (int i = slice[sn]; i < slice[sn + win]; i++) {
|
||||||
sumX += resX[sorted_idx[i]];
|
const int idx = sorted_idx[i];
|
||||||
sumY += resY[sorted_idx[i]];
|
sumX += resX[idx];
|
||||||
|
sumY += resY[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
float norm = sumX * sumX + sumY * sumY;
|
float norm = sumX * sumX + sumY * sumY;
|
||||||
@ -1347,12 +1357,14 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
|
|||||||
|
|
||||||
float sumX = 0.0f, sumY = 0.0f;
|
float sumX = 0.0f, sumY = 0.0f;
|
||||||
for (int i = slice[sn]; i < slice[slices]; i++) {
|
for (int i = slice[sn]; i < slice[slices]; i++) {
|
||||||
sumX += resX[sorted_idx[i]];
|
const int idx = sorted_idx[i];
|
||||||
sumY += resY[sorted_idx[i]];
|
sumX += resX[idx];
|
||||||
|
sumY += resY[idx];
|
||||||
}
|
}
|
||||||
for (int i = slice[0]; i < slice[remain]; i++) {
|
for (int i = slice[0]; i < slice[remain]; i++) {
|
||||||
sumX += resX[sorted_idx[i]];
|
const int idx = sorted_idx[i];
|
||||||
sumY += resY[sorted_idx[i]];
|
sumX += resX[idx];
|
||||||
|
sumY += resY[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
float norm = sumX * sumX + sumY * sumY;
|
float norm = sumX * sumX + sumY * sumY;
|
||||||
|
Loading…
Reference in New Issue
Block a user