refactor imgproc/utils (#2766)
* refactor imgproc/utils * const * space * return valuepull/19510/head
parent
cb238fd2ee
commit
554ea8f54a
3 changed files with 25 additions and 35 deletions
@ -1,43 +1,36 @@ |
|||||||
#include "utils.h" |
#include "utils.h" |
||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
#include <algorithm> |
#include <algorithm> |
||||||
|
#include <cmath> |
||||||
// calculate score based on laplacians in one area
|
// calculate score based on laplacians in one area
|
||||||
void get_lapmap_one(int16_t *lap, uint16_t *res, int x_pitch, int y_pitch) { |
uint16_t get_lapmap_one(const int16_t *lap, int x_pitch, int y_pitch) { |
||||||
int size = x_pitch * y_pitch; |
const int size = x_pitch * y_pitch; |
||||||
// avg and max of roi
|
// avg and max of roi
|
||||||
float fsum = 0; |
int16_t max = 0; |
||||||
int16_t mean, max; |
int sum = 0; |
||||||
max = 0; |
for (int i = 0; i < size; ++i) { |
||||||
|
const int16_t v = lap[i % x_pitch + (i / x_pitch) * x_pitch]; |
||||||
for (int i = 0; i < size; i++) { |
sum += v; |
||||||
int x_offset = i % x_pitch; |
if (v > max) max = v; |
||||||
int y_offset = i / x_pitch; |
|
||||||
fsum += lap[x_offset + y_offset*x_pitch]; |
|
||||||
max = std::max(lap[x_offset + y_offset*x_pitch], max); |
|
||||||
} |
} |
||||||
|
|
||||||
mean = fsum / size; |
const int16_t mean = sum / size; |
||||||
|
|
||||||
// var of roi
|
// var of roi
|
||||||
float fvar = 0; |
int var = 0; |
||||||
for (int i = 0; i < size; i++) { |
for (int i = 0; i < size; ++i) { |
||||||
int x_offset = i % x_pitch; |
var += std::pow(lap[i % x_pitch + (i / x_pitch) * x_pitch] - mean, 2); |
||||||
int y_offset = i / x_pitch; |
|
||||||
fvar += (float)((lap[x_offset + y_offset*x_pitch] - mean) * (lap[x_offset + y_offset*x_pitch] - mean)); |
|
||||||
} |
} |
||||||
|
|
||||||
fvar = fvar / size; |
const float fvar = (float)var / size; |
||||||
|
return std::min(5 * fvar + max, (float)65535); |
||||||
*res = std::min(5 * fvar + max, (float)65535); |
|
||||||
} |
} |
||||||
|
|
||||||
bool is_blur(uint16_t *lapmap) { |
bool is_blur(const uint16_t *lapmap, const size_t size) { |
||||||
int n_roi = (ROI_X_MAX - ROI_X_MIN + 1) * (ROI_Y_MAX - ROI_Y_MIN + 1); |
|
||||||
float bad_sum = 0; |
float bad_sum = 0; |
||||||
for (int i = 0; i < n_roi; i++) { |
for (int i = 0; i < size; i++) { |
||||||
if (*(lapmap + i) < LM_THRESH) { |
if (lapmap[i] < LM_THRESH) { |
||||||
bad_sum += 1/(float)n_roi; |
bad_sum += 1 / (float)size; |
||||||
} |
} |
||||||
} |
} |
||||||
return (bad_sum > LM_PREC_THRESH); |
return (bad_sum > LM_PREC_THRESH); |
||||||
|
Loading…
Reference in new issue