From 5e137faef5ead4894838780f1a3475205a4602fe Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 8 Jun 2021 14:48:46 +0200 Subject: [PATCH] [ADD] up left and right detection regions --- src/computervision/HandDetectRegion.cpp | 2 +- src/computervision/HandDetectRegion.h | 10 +++++++ src/computervision/ObjectDetection.cpp | 2 +- .../calibration/HandCalibrator.cpp | 5 +++- src/scenes/in_Game_Scene.cpp | 28 +++++++++++++------ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/computervision/HandDetectRegion.cpp b/src/computervision/HandDetectRegion.cpp index f789db6..9c451a9 100644 --- a/src/computervision/HandDetectRegion.cpp +++ b/src/computervision/HandDetectRegion.cpp @@ -37,7 +37,7 @@ namespace computervision imshow("handMask" + region_id, handMask); /*imshow("handDetection", fingerCountDebug);*/ - hand_present = hand_calibrator.CheckIfHandPresent(handMask); + hand_present = hand_calibrator.CheckIfHandPresent(handMask,handcalibration::HandDetectionType::GAME); std::string text = (hand_present ? "hand" : "no"); cv::putText(camera_frame, text, cv::Point(start_x_pos, start_y_pos), cv::FONT_HERSHEY_COMPLEX, 2.0, cv::Scalar(0, 255, 255), 2); hand_calibrator.SetHandPresent(hand_present); diff --git a/src/computervision/HandDetectRegion.h b/src/computervision/HandDetectRegion.h index 3594ff3..7cc1a9a 100644 --- a/src/computervision/HandDetectRegion.h +++ b/src/computervision/HandDetectRegion.h @@ -14,6 +14,16 @@ namespace computervision public: HandDetectRegion(std::string id,int x_pos, int y_pos, int width, int height); + void SetXPos(int x) { start_x_pos = x; } + void SetYPos(int y) { start_y_pos = y; } + int GetXPos() { return start_x_pos; } + int GetYPos() { return start_y_pos; } + + void SetWidth(int width) { region_width = width; } + void SetHeigth(int height) { region_height = height; } + int GetWidth() { return region_width; } + int GetHeight() { return region_height; } + cv::Mat GenerateHandMaskSquare(cv::Mat img); void DetectHand(cv::Mat& camera_frame); diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 530e474..155512e 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -74,7 +74,7 @@ namespace computervision imshow("handMask", handMask); imshow("handDetection", fingerCountDebug);*/ - hand_present = hand_calibrator.CheckIfHandPresent(handMask); + hand_present = hand_calibrator.CheckIfHandPresent(handMask,handcalibration::HandDetectionType::MENU); hand_calibrator.SetHandPresent(hand_present); diff --git a/src/computervision/calibration/HandCalibrator.cpp b/src/computervision/calibration/HandCalibrator.cpp index 86f3aa5..caa4d03 100644 --- a/src/computervision/calibration/HandCalibrator.cpp +++ b/src/computervision/calibration/HandCalibrator.cpp @@ -1,8 +1,9 @@ #include "HandCalibrator.h" +#include #define MIN_MENU_HAND_SIZE 10000 -#define MIN_GAME_HAND_SIZE 10000 // todo change +#define MIN_GAME_HAND_SIZE 4000 // todo change namespace computervision { namespace handcalibration @@ -64,9 +65,11 @@ namespace computervision if (points.size() == 0) return false; + std::cout << std::endl; for (int p = 0; p < points.size(); p++) { int area = cv::contourArea(points[p]); + std::cout << area << std::endl; if (type == handcalibration::HandDetectionType::MENU) if (area > MIN_MENU_HAND_SIZE) return true; diff --git a/src/scenes/in_Game_Scene.cpp b/src/scenes/in_Game_Scene.cpp index bbadf93..0eede19 100644 --- a/src/scenes/in_Game_Scene.cpp +++ b/src/scenes/in_Game_Scene.cpp @@ -26,10 +26,10 @@ namespace scene entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); std::vector guis; + std::vector regions; computervision::ObjectDetection objDetect; - computervision::HandDetectRegion reg1("left", 20, 100, 150, 150); - computervision::HandDetectRegion reg2("right", 200, 200, 150, 150); + computervision::HandDetectRegion reg_left("left", 0, 0, 150, 150), reg_right("right", 0, 0, 150, 150), reg_up("up", 0, 0, 150, 150); In_Game_Scene::In_Game_Scene() @@ -44,6 +44,15 @@ namespace scene scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window) { + cv::Mat camera_frame = objDetect.ReadCamera(); // 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); + + raw_model = render_engine::LoadObjModel("res/House.obj"); texture = { render_engine::loader::LoadTexture("res/Texture.png") }; texture.shine_damper = 10; @@ -125,22 +134,25 @@ namespace scene if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS) { - reg1.CalibrateBackground(); - reg2.CalibrateBackground(); + reg_left.CalibrateBackground(); + reg_right.CalibrateBackground(); + reg_up.CalibrateBackground(); } if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { - std::vector tresholds = reg1.CalculateSkinTresholds(); - reg2.setSkinTresholds(tresholds); + std::vector tresholds = reg_left.CalculateSkinTresholds(); + reg_right.setSkinTresholds(tresholds); + reg_up.setSkinTresholds(tresholds); } } void scene::In_Game_Scene::update_hand_detection() { cv::Mat camera_frame = objDetect.ReadCamera(); - reg1.DetectHand(camera_frame); - reg2.DetectHand(camera_frame); + reg_left.DetectHand(camera_frame); + reg_right.DetectHand(camera_frame); + reg_up.DetectHand(camera_frame); cv::imshow("camera", camera_frame); }