[ADD] up left and right detection regions

This commit is contained in:
Sem van der Hoeven
2021-06-08 14:48:46 +02:00
parent cadee7d8e9
commit 5e137faef5
5 changed files with 36 additions and 11 deletions

View File

@@ -37,7 +37,7 @@ namespace computervision
imshow("handMask" + region_id, handMask); imshow("handMask" + region_id, handMask);
/*imshow("handDetection", fingerCountDebug);*/ /*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"); 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); 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); hand_calibrator.SetHandPresent(hand_present);

View File

@@ -14,6 +14,16 @@ namespace computervision
public: public:
HandDetectRegion(std::string id,int x_pos, int y_pos, int width, int height); 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); cv::Mat GenerateHandMaskSquare(cv::Mat img);
void DetectHand(cv::Mat& camera_frame); void DetectHand(cv::Mat& camera_frame);

View File

@@ -74,7 +74,7 @@ namespace computervision
imshow("handMask", handMask); imshow("handMask", handMask);
imshow("handDetection", fingerCountDebug);*/ imshow("handDetection", fingerCountDebug);*/
hand_present = hand_calibrator.CheckIfHandPresent(handMask); hand_present = hand_calibrator.CheckIfHandPresent(handMask,handcalibration::HandDetectionType::MENU);
hand_calibrator.SetHandPresent(hand_present); hand_calibrator.SetHandPresent(hand_present);

View File

@@ -1,8 +1,9 @@
#include "HandCalibrator.h" #include "HandCalibrator.h"
#include <iostream>
#define MIN_MENU_HAND_SIZE 10000 #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 computervision
{ {
namespace handcalibration namespace handcalibration
@@ -64,9 +65,11 @@ namespace computervision
if (points.size() == 0) return false; if (points.size() == 0) return false;
std::cout << std::endl;
for (int p = 0; p < points.size(); p++) for (int p = 0; p < points.size(); p++)
{ {
int area = cv::contourArea(points[p]); int area = cv::contourArea(points[p]);
std::cout << area << std::endl;
if (type == handcalibration::HandDetectionType::MENU) if (type == handcalibration::HandDetectionType::MENU)
if (area > MIN_MENU_HAND_SIZE) return true; if (area > MIN_MENU_HAND_SIZE) return true;

View File

@@ -26,10 +26,10 @@ namespace scene
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
std::vector<gui::GuiTexture*> guis; std::vector<gui::GuiTexture*> guis;
std::vector<computervision::HandDetectRegion> regions; std::vector<computervision::HandDetectRegion> regions;
computervision::ObjectDetection objDetect; computervision::ObjectDetection objDetect;
computervision::HandDetectRegion reg1("left", 20, 100, 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);
computervision::HandDetectRegion reg2("right", 200, 200, 150, 150);
In_Game_Scene::In_Game_Scene() In_Game_Scene::In_Game_Scene()
@@ -44,6 +44,15 @@ namespace scene
scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window) 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"); raw_model = render_engine::LoadObjModel("res/House.obj");
texture = { render_engine::loader::LoadTexture("res/Texture.png") }; texture = { render_engine::loader::LoadTexture("res/Texture.png") };
texture.shine_damper = 10; texture.shine_damper = 10;
@@ -125,22 +134,25 @@ namespace scene
if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS)
{ {
reg1.CalibrateBackground(); reg_left.CalibrateBackground();
reg2.CalibrateBackground(); reg_right.CalibrateBackground();
reg_up.CalibrateBackground();
} }
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
{ {
std::vector<int> tresholds = reg1.CalculateSkinTresholds(); std::vector<int> tresholds = reg_left.CalculateSkinTresholds();
reg2.setSkinTresholds(tresholds); reg_right.setSkinTresholds(tresholds);
reg_up.setSkinTresholds(tresholds);
} }
} }
void scene::In_Game_Scene::update_hand_detection() void scene::In_Game_Scene::update_hand_detection()
{ {
cv::Mat camera_frame = objDetect.ReadCamera(); cv::Mat camera_frame = objDetect.ReadCamera();
reg1.DetectHand(camera_frame); reg_left.DetectHand(camera_frame);
reg2.DetectHand(camera_frame); reg_right.DetectHand(camera_frame);
reg_up.DetectHand(camera_frame);
cv::imshow("camera", camera_frame); cv::imshow("camera", camera_frame);
} }