From a8996f63ef50177615893c7c88e220b35c7b2ba2 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 8 Jun 2021 16:06:46 +0200 Subject: [PATCH] [ADD] start game scene fingers --- src/computervision/HandDetectRegion.h | 1 - src/computervision/ObjectDetection.cpp | 13 ++++--------- src/computervision/calibration/StaticSkinTreshold.h | 10 ---------- src/scenes/in_Game_Scene.cpp | 7 ++++--- src/scenes/startup_Scene.cpp | 6 ++++-- wk2_fps.vcxproj | 1 + wk2_fps.vcxproj.filters | 1 + 7 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 src/computervision/calibration/StaticSkinTreshold.h diff --git a/src/computervision/HandDetectRegion.h b/src/computervision/HandDetectRegion.h index 067badd..7cc1a9a 100644 --- a/src/computervision/HandDetectRegion.h +++ b/src/computervision/HandDetectRegion.h @@ -7,7 +7,6 @@ #include "BackgroundRemover.h" #include "SkinDetector.h" #include "FingerCount.h" -#include "calibration/StaticSkinTreshold.h" namespace computervision { class HandDetectRegion diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index ad3e13e..829953c 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -10,8 +10,6 @@ #include "async/StaticCameraInstance.h" #include "calibration/HandCalibrator.h" -#include "calibration/StaticSkinTreshold.h" - namespace computervision { @@ -64,12 +62,15 @@ namespace computervision // draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed. DrawHandMask(&camera_frame); + hand_calibrator.SetAmountOfFingers(fingers_amount); finger_count.DrawHandContours(camera_frame); hand_calibrator.DrawHandCalibrationText(camera_frame); imshow("camera", camera_frame); + + /*imshow("output", frame_out); imshow("foreground", foreground); imshow("handMask", handMask); @@ -89,13 +90,7 @@ namespace computervision } else if (key == 115) // s, calibrate the skin color { - std::vector treshold = skin_detector.calibrateAndReturn(input_frame); - StaticSkinTreshold::hLowThreshold = treshold[0]; - StaticSkinTreshold::hHighThreshold = treshold[1]; - StaticSkinTreshold::sLowThreshold = treshold[2]; - StaticSkinTreshold::sHighThreshold = treshold[3]; - StaticSkinTreshold::vLowThreshold = treshold[4]; - StaticSkinTreshold::vHighThreshold = treshold[5]; + skin_detector.calibrate(input_frame); hand_calibrator.SetSkinCalibration(true); } diff --git a/src/computervision/calibration/StaticSkinTreshold.h b/src/computervision/calibration/StaticSkinTreshold.h deleted file mode 100644 index cfce1f7..0000000 --- a/src/computervision/calibration/StaticSkinTreshold.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -namespace StaticSkinTreshold -{ - static int hLowThreshold, - hHighThreshold, - sLowThreshold, - sHighThreshold, - vLowThreshold, - vHighThreshold; -}; diff --git a/src/scenes/in_Game_Scene.cpp b/src/scenes/in_Game_Scene.cpp index 48d099b..f0d5946 100644 --- a/src/scenes/in_Game_Scene.cpp +++ b/src/scenes/in_Game_Scene.cpp @@ -28,7 +28,6 @@ namespace scene std::vector regions; - computervision::ObjectDetection objDetect; computervision::HandDetectRegion reg_left("left", 0, 0, 150, 150), reg_right("right", 0, 0, 150, 150), reg_up("up", 0, 0, 150, 150); @@ -45,7 +44,8 @@ namespace scene scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window) { // set up squares according to size of camera input - cv::Mat camera_frame = objDetect.ReadCamera(); // get camera frame to know the width and heigth + 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()); @@ -151,7 +151,8 @@ namespace scene void scene::In_Game_Scene::update_hand_detection() { - cv::Mat camera_frame = objDetect.ReadCamera(); + cv::Mat camera_frame; + static_camera::getCap().read(camera_frame); reg_left.DetectHand(camera_frame); reg_right.DetectHand(camera_frame); reg_up.DetectHand(camera_frame); diff --git a/src/scenes/startup_Scene.cpp b/src/scenes/startup_Scene.cpp index 7ef51db..a492c18 100644 --- a/src/scenes/startup_Scene.cpp +++ b/src/scenes/startup_Scene.cpp @@ -8,7 +8,7 @@ namespace scene { - + computervision::ObjectDetection objDetect; scene::Scenes scene::Startup_Scene::start(GLFWwindow *window) { while (return_value == scene::Scenes::STARTUP) @@ -30,7 +30,8 @@ namespace scene void scene::Startup_Scene::update(GLFWwindow* window) { - + bool hand_present; + objDetect.DetectHand(objDetect.ReadCamera(),hand_present); } void scene::Startup_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods) @@ -38,6 +39,7 @@ namespace scene if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { return_value = scene::Scenes::INGAME; + cv::destroyWindow("camera"); } } } diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 4d0fabf..28b43a2 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -47,6 +47,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index 3e9201f..abb170d 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -56,6 +56,7 @@ +