Skip to content

Commit

Permalink
Add threshold option
Browse files Browse the repository at this point in the history
  • Loading branch information
nagadomi committed Feb 17, 2017
1 parent 41a7ffb commit a01c02c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions animeface-ruby/animeface.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static VALUE cMagick;
#define NV_ANIMEFACE_WINDOW_SIZE 42.592f
#define NV_ANIMEFACE_STEP 4.0f
#define NV_ANIMEFACE_SCALE_FACTOR 1.095f
#define NV_ANIMEFACE_THRESHOLD 0.5f

static void
nv_conv_imager2nv(nv_matrix_t *bgr, nv_matrix_t *gray,
Expand Down Expand Up @@ -86,7 +87,8 @@ nv_conv_imager2nv(nv_matrix_t *bgr, nv_matrix_t *gray,

VALUE detect(VALUE im,
float min_window_size,
float step, float scale_factor)
float step, float scale_factor,
float threshold)
{
static const nv_mlp_t *detector_mlp = &nv_face_mlp_face_00;
static const nv_mlp_t *face_mlp[] = {
Expand Down Expand Up @@ -145,7 +147,7 @@ VALUE detect(VALUE im,
dir_mlp,
detector_mlp, face_mlp, 2,
parts_mlp,
step, scale_factor, min_window_size
step, scale_factor, min_window_size, threshold
);
// analyze face
for (i = 0; i < nface; ++i) {
Expand Down Expand Up @@ -276,7 +278,7 @@ float get_option(VALUE hash, const char *key, float defvalue)
static VALUE
wrap_detect(int argc, VALUE *argv)
{
float min_window_size, step, scale_factor;
float min_window_size, step, scale_factor, threshold;
VALUE im, options;

if (rb_scan_args(argc, argv, "11", &im, &options) == 2) {
Expand All @@ -285,13 +287,15 @@ wrap_detect(int argc, VALUE *argv)
min_window_size = get_option(options, "min_window_size", NV_ANIMEFACE_WINDOW_SIZE);
step = get_option(options, "step", NV_ANIMEFACE_STEP);
scale_factor = get_option(options, "scale_factor", NV_ANIMEFACE_SCALE_FACTOR);
threshold = get_option(options, "threshold", NV_ANIMEFACE_THRESHOLD);
} else {
min_window_size = NV_ANIMEFACE_WINDOW_SIZE;
step = NV_ANIMEFACE_STEP;
scale_factor = NV_ANIMEFACE_SCALE_FACTOR;
threshold = NV_ANIMEFACE_THRESHOLD;
}

return detect(im, min_window_size, step, scale_factor);
return detect(im, min_window_size, step, scale_factor, threshold);
}

void Init_AnimeFace()
Expand Down
5 changes: 3 additions & 2 deletions nvxs/nv_face/nv_face_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ nv_face_detect(nv_face_position_t *face_pos,
const nv_mlp_t *parts_mlp,
float step,
float scale_factor,
float min_window_size
float min_window_size,
float threshold
)
{
nv_candidate candidates[NV_FACE_DETECT_MAX_CANDIDATES] = {0}; // max
Expand Down Expand Up @@ -101,7 +102,7 @@ nv_face_detect(nv_face_position_t *face_pos,
// 顔判別2
z = nv_mlp_bagging_predict_d(bagging_mlp, bagging_mlps, haar[thread_idx], 0, 0);
}
if (z > 0.5) {
if (z > threshold) {
// 顔
#ifdef _OPENMP
#pragma omp critical
Expand Down
3 changes: 2 additions & 1 deletion nvxs/nv_face/nv_face_detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ int nv_face_detect(nv_face_position_t *face_pos,
const nv_mlp_t *parts_mlp,
float step,
float scale_factor,
float min_window_size
float min_window_size,
float threshold
);

#if NV_ENABLE_CUDA
Expand Down

0 comments on commit a01c02c

Please sign in to comment.