[ADD] start game scene fingers

This commit is contained in:
Sem van der Hoeven
2021-06-08 16:06:46 +02:00
parent 88252f4dc8
commit a8996f63ef
7 changed files with 14 additions and 25 deletions

View File

@@ -7,7 +7,6 @@
#include "BackgroundRemover.h" #include "BackgroundRemover.h"
#include "SkinDetector.h" #include "SkinDetector.h"
#include "FingerCount.h" #include "FingerCount.h"
#include "calibration/StaticSkinTreshold.h"
namespace computervision namespace computervision
{ {
class HandDetectRegion class HandDetectRegion

View File

@@ -10,8 +10,6 @@
#include "async/StaticCameraInstance.h" #include "async/StaticCameraInstance.h"
#include "calibration/HandCalibrator.h" #include "calibration/HandCalibrator.h"
#include "calibration/StaticSkinTreshold.h"
namespace computervision namespace computervision
{ {
@@ -65,11 +63,14 @@ namespace computervision
// draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed. // draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed.
DrawHandMask(&camera_frame); DrawHandMask(&camera_frame);
hand_calibrator.SetAmountOfFingers(fingers_amount); hand_calibrator.SetAmountOfFingers(fingers_amount);
finger_count.DrawHandContours(camera_frame); finger_count.DrawHandContours(camera_frame);
hand_calibrator.DrawHandCalibrationText(camera_frame); hand_calibrator.DrawHandCalibrationText(camera_frame);
imshow("camera", camera_frame); imshow("camera", camera_frame);
/*imshow("output", frame_out); /*imshow("output", frame_out);
imshow("foreground", foreground); imshow("foreground", foreground);
imshow("handMask", handMask); imshow("handMask", handMask);
@@ -89,13 +90,7 @@ namespace computervision
} }
else if (key == 115) // s, calibrate the skin color else if (key == 115) // s, calibrate the skin color
{ {
std::vector<int> treshold = skin_detector.calibrateAndReturn(input_frame); skin_detector.calibrate(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];
hand_calibrator.SetSkinCalibration(true); hand_calibrator.SetSkinCalibration(true);
} }

View File

@@ -1,10 +0,0 @@
#pragma once
namespace StaticSkinTreshold
{
static int hLowThreshold,
hHighThreshold,
sLowThreshold,
sHighThreshold,
vLowThreshold,
vHighThreshold;
};

View File

@@ -28,7 +28,6 @@ namespace scene
std::vector<computervision::HandDetectRegion> regions; std::vector<computervision::HandDetectRegion> 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); 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) scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window)
{ {
// set up squares according to size of camera input // 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.SetXPos(10);
reg_left.SetYPos(camera_frame.rows / 2 - reg_left.GetHeight()/2); reg_left.SetYPos(camera_frame.rows / 2 - reg_left.GetHeight()/2);
reg_right.SetXPos(camera_frame.cols - 10 - reg_right.GetWidth()); reg_right.SetXPos(camera_frame.cols - 10 - reg_right.GetWidth());
@@ -151,7 +151,8 @@ namespace scene
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;
static_camera::getCap().read(camera_frame);
reg_left.DetectHand(camera_frame); reg_left.DetectHand(camera_frame);
reg_right.DetectHand(camera_frame); reg_right.DetectHand(camera_frame);
reg_up.DetectHand(camera_frame); reg_up.DetectHand(camera_frame);

View File

@@ -8,7 +8,7 @@
namespace scene namespace scene
{ {
computervision::ObjectDetection objDetect;
scene::Scenes scene::Startup_Scene::start(GLFWwindow *window) scene::Scenes scene::Startup_Scene::start(GLFWwindow *window)
{ {
while (return_value == scene::Scenes::STARTUP) while (return_value == scene::Scenes::STARTUP)
@@ -30,7 +30,8 @@ namespace scene
void scene::Startup_Scene::update(GLFWwindow* window) 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) 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) if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
{ {
return_value = scene::Scenes::INGAME; return_value = scene::Scenes::INGAME;
cv::destroyWindow("camera");
} }
} }
} }

View File

@@ -47,6 +47,7 @@
<ClInclude Include="src\collision\collision.h" /> <ClInclude Include="src\collision\collision.h" />
<ClInclude Include="src\collision\collision_handler.h" /> <ClInclude Include="src\collision\collision_handler.h" />
<ClInclude Include="src\computervision\calibration\HandCalibrator.h" /> <ClInclude Include="src\computervision\calibration\HandCalibrator.h" />
<ClInclude Include="src\computervision\calibration\StaticSkinTreshold.h" />
<ClInclude Include="src\computervision\HandDetectRegion.h" /> <ClInclude Include="src\computervision\HandDetectRegion.h" />
<ClInclude Include="src\scenes\in_Game_Scene.h" /> <ClInclude Include="src\scenes\in_Game_Scene.h" />
<ClInclude Include="src\scenes\scene.h" /> <ClInclude Include="src\scenes\scene.h" />

View File

@@ -56,6 +56,7 @@
<ClInclude Include="src\scenes\startup_Scene.h" /> <ClInclude Include="src\scenes\startup_Scene.h" />
<ClInclude Include="src\computervision\calibration\HandCalibrator.h" /> <ClInclude Include="src\computervision\calibration\HandCalibrator.h" />
<ClInclude Include="src\computervision\HandDetectRegion.h" /> <ClInclude Include="src\computervision\HandDetectRegion.h" />
<ClInclude Include="src\computervision\calibration\StaticSkinTreshold.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" /> <Xml Include="res\haarcascade_frontalface_alt.xml" />