[FIX] auto skin calibration in game scene
This commit is contained in:
@@ -56,10 +56,8 @@ namespace computervision
|
||||
|
||||
if (!skin_calibrated)
|
||||
{
|
||||
skin_detector.calibrate(input_frame);
|
||||
skin_calibrated = true;
|
||||
hand_calibrator.SetSkinCalibration(skin_calibrated);
|
||||
time = 0;
|
||||
if (is_main_skin_detection_region)
|
||||
skin_timer_callback();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +133,8 @@ namespace computervision
|
||||
{
|
||||
std::cout << "calibrating skin " << region_id << std::endl;
|
||||
hand_calibrator.SetSkinCalibration(true);
|
||||
skin_calibrated = true;
|
||||
time = 0;
|
||||
return skin_detector.calibrateAndReturn(frame_out);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,8 @@ namespace computervision
|
||||
std::cout << "setting skin " << region_id << std::endl;
|
||||
skin_detector.setTresholds(tresholds);
|
||||
hand_calibrator.SetSkinCalibration(true);
|
||||
skin_calibrated = true;
|
||||
time = 0;
|
||||
}
|
||||
|
||||
void HandDetectRegion::UpdateTime(float delta_time)
|
||||
|
||||
@@ -39,6 +39,8 @@ namespace computervision
|
||||
|
||||
void setSkinTresholds(std::vector<int>& tresholds);
|
||||
void UpdateTime(float delta_time);
|
||||
void SetMainSkinDetecRegion(bool val) { is_main_skin_detection_region = val; };
|
||||
void SetSkinTimerCallback(std::function<void()> fun) { skin_timer_callback = fun; };
|
||||
|
||||
private:
|
||||
|
||||
@@ -61,6 +63,8 @@ namespace computervision
|
||||
|
||||
bool background_calibrated = false;
|
||||
bool skin_calibrated = false;
|
||||
bool is_main_skin_detection_region = false;
|
||||
std::function<void()> skin_timer_callback;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -102,6 +102,29 @@ namespace scene
|
||||
delete house_generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets up the hand detection regions and sets the callbacks for the skin calibration.
|
||||
*
|
||||
*/
|
||||
void In_Game_Scene::SetupHandDetection()
|
||||
{
|
||||
// set up squares according to size of camera input
|
||||
cv::Mat camera_frame;
|
||||
static_camera::getCap().read(camera_frame); // get camera frame to know the width and heigth
|
||||
|
||||
reg_left.SetMainSkinDetecRegion(true);
|
||||
reg_right.SetMainSkinDetecRegion(false);
|
||||
reg_right.SetMainSkinDetecRegion(false);
|
||||
std::function<void()> callback = [this]() {OnSkinCalibrationCallback(); };
|
||||
reg_left.SetSkinTimerCallback(callback);
|
||||
|
||||
reg_left.SetXPos(10);
|
||||
reg_left.SetYPos(camera_frame.rows / 2 - reg_left.GetHeight() / 2);
|
||||
reg_right.SetXPos(camera_frame.cols - 10 - reg_right.GetWidth());
|
||||
reg_right.SetYPos(camera_frame.rows / 2 - reg_right.GetHeight() / 2);
|
||||
reg_up.SetXPos(camera_frame.cols / 2 - reg_up.GetWidth() / 2);
|
||||
reg_up.SetYPos(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief loads a new chunk in front of the camera, and deletes the chunk behind the camera.
|
||||
@@ -112,16 +135,6 @@ namespace scene
|
||||
void load_chunk(int model_pos)
|
||||
{
|
||||
static unsigned int furniture_count = 0;
|
||||
|
||||
// set up squares according to size of camera input
|
||||
cv::Mat camera_frame;
|
||||
static_camera::getCap().read(camera_frame); // get camera frame to know the width and heigth
|
||||
reg_left.SetXPos(10);
|
||||
reg_left.SetYPos(camera_frame.rows / 2 - reg_left.GetHeight() / 2);
|
||||
reg_right.SetXPos(camera_frame.cols - 10 - reg_right.GetWidth());
|
||||
reg_right.SetYPos(camera_frame.rows / 2 - reg_right.GetHeight() / 2);
|
||||
reg_up.SetXPos(camera_frame.cols / 2 - reg_up.GetWidth() / 2);
|
||||
reg_up.SetYPos(10);
|
||||
std::cout << "loading model chunk" << std::endl;
|
||||
if (house_models.size() >= MAX_MODEL_DEQUE_SIZE * furniture_count)
|
||||
{
|
||||
@@ -156,6 +169,9 @@ namespace scene
|
||||
main_character = std::make_shared<entities::MainCharacter>(model_char, glm::vec3(0, -50, -100), glm::vec3(0, 90, 0), 5, char_box);
|
||||
collision_entities.push_back(main_character);
|
||||
house_generator = new entities::HouseGenerator();
|
||||
|
||||
SetupHandDetection();
|
||||
|
||||
// load the first few house models
|
||||
for (int i = 0; i <= UPCOMING_MODEL_AMOUNT; i++)
|
||||
{
|
||||
@@ -343,6 +359,14 @@ namespace scene
|
||||
cv::imshow("camera", camera_frame);
|
||||
}
|
||||
|
||||
void scene::In_Game_Scene::OnSkinCalibrationCallback()
|
||||
{
|
||||
std::cout << "on skin calibration callback" << std::endl;
|
||||
std::vector<int> tresholds = reg_left.CalculateSkinTresholds();
|
||||
reg_right.setSkinTresholds(tresholds);
|
||||
reg_up.setSkinTresholds(tresholds);
|
||||
}
|
||||
|
||||
//renders the models for the pause menu
|
||||
void In_Game_Scene::render_pause_menu()
|
||||
{
|
||||
@@ -356,9 +380,9 @@ namespace scene
|
||||
|
||||
toolbox::GetDigitsFromNumber(score, digits);
|
||||
|
||||
for (int i = digits.size()-1; i >= 0; i--)
|
||||
for (int i = digits.size() - 1; i >= 0; i--)
|
||||
{
|
||||
score_textures[digits[i]].get()->position.x = 0.15 * i -0.9;
|
||||
score_textures[digits[i]].get()->position.x = 0.15 * i - 0.9;
|
||||
render_engine::renderer::Render(score_textures[digits[i]], *gui_shader);
|
||||
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@ namespace scene
|
||||
void render_pause_menu();
|
||||
void update_hand_detection();
|
||||
|
||||
void SetupHandDetection();
|
||||
void OnSkinCalibrationCallback();
|
||||
|
||||
public:
|
||||
In_Game_Scene();
|
||||
~In_Game_Scene();
|
||||
|
||||
Reference in New Issue
Block a user