#!/usr/bin/env python
PACKAGE = "person_detector"
NS = "FaceDetector"
param_file = "person_detector_params.yaml"

import rospkg
rospack = rospkg.RosPack()
gen_param_file = rospack.get_path('image_utils') + '/cfg/general_params.yaml'

from dynamic_reconfigure.parameter_generator_catkin import *
import yaml
import os

Dir = os.path.dirname(os.path.realpath(__file__))

params = {}
with open(Dir+'/'+param_file, 'r') as stream:
  try:
    params = yaml.load(stream)
  except yaml.YAMLERROR as e:
    print e

gen_params = {}
with open(gen_param_file, 'r') as stream:
  try:
    gen_params = yaml.load(stream)
  except yaml.YAMLERROR as e:
    print e

gen = ParameterGenerator()

# Level 0
p = gen_params
gen.add("gpu",                 bool_t,      0,   "GPU Active",          p['gpu'])

# Level 1
p = params[NS]
gen.add("min_dist_pct",      double_t,      1,   "Head Min Distance",   p['min_dist_pct'],     0.05,   0.95)

# Level 2
p = params[NS]['face']
gen.add("f_scale_factor",    double_t,      2,   "F Scale Factor",      p['scale_factor'],   1.01,     5)
gen.add("f_min_neighbors",      int_t,      2,   "F Min Neighbors",     p['min_neighbors'],      1,    30)
gen.add("f_min_size",           int_t,      2,   "F Min Size",          p['min_size'][0],     20,   300)
gen.add("f_max_size",           int_t,      2,   "F Max Size",          p['max_size'][0],     20,   300)

# Level 3
p = params[NS]['profile']
gen.add("p_scale_factor",    double_t,      3,   "P Scale Factor",      p['scale_factor'],   1.01,     5)
gen.add("p_min_neighbors",      int_t,      3,   "P Min Neighbors",     p['min_neighbors'],      1,    30)
gen.add("p_min_size",           int_t,      3,   "P Min Size",          p['min_size'][0],     20,   300)
gen.add("p_max_size",           int_t,      3,   "P Max Size",          p['max_size'][0],     20,   300)

# Level 4
p = params[NS]['hog']
gen.add("h_win_size",           int_t,      4,   "HOG Win Size",        p['win_size'][0],     32,   256)
gen.add("h_win_stride",         int_t,      4,   "HOG Win Stride",      p['win_stride'],      1,    10)
gen.add("h_block_size",         int_t,      4,   "HOG Block Size",      p['block_size'][0],      3,    20)
gen.add("h_block_stride",       int_t,      4,   "HOG Block Stride",    p['block_stride'][0],      3,    20)
gen.add("h_cell_size",          int_t,      4,   "HOG Cell Size",       p['cell_size'][0],      3,    20)
gen.add("h_bins",               int_t,      4,   "HOG Bins",            p['bins'],      1,     9)
gen.add("h_nlvls",              int_t,      4,   "HOG Number of Levels",p['nlvls'],      5,   100)
gen.add("h_scale_factor",    double_t,      4,   "HOG Scale Factor",    p['scale_factor'],   1.01,     5)
gen.add("h_hit_thresh",      double_t,      4,   "HOG Hit Threshold",   p['hit_thr'],      0,     2)

exit(gen.generate(PACKAGE, NS, "FaceDetectorRQT"))
