[ADD] hand detection type enum
This commit is contained in:
@@ -29,23 +29,11 @@ namespace computervision
|
||||
// detect the hand contours
|
||||
handMask = skin_detector.getSkinMask(foreground);
|
||||
|
||||
// count the amount of fingers and put the info on the matrix
|
||||
//fingerCountDebug = finger_count.findFingersCount(handMask, frame_out);
|
||||
|
||||
//// get the amount of fingers
|
||||
//int fingers_amount = finger_count.getAmountOfFingers();
|
||||
|
||||
// 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" + region_id, frame_out);
|
||||
imshow("foreground" + region_id, foreground);
|
||||
//imshow("output" + region_id, frame_out);
|
||||
//imshow("foreground" + region_id, foreground);
|
||||
imshow("handMask" + region_id, handMask);
|
||||
/*imshow("handDetection", fingerCountDebug);*/
|
||||
|
||||
@@ -83,6 +71,7 @@ namespace computervision
|
||||
|
||||
void HandDetectRegion::CalibrateBackground()
|
||||
{
|
||||
std::cout << "calibrating background " << region_id << std::endl;
|
||||
background_remover.calibrate(frame_out);
|
||||
hand_calibrator.SetBackGroundCalibrated(true);
|
||||
}
|
||||
@@ -94,11 +83,13 @@ namespace computervision
|
||||
|
||||
std::vector<int> HandDetectRegion::CalculateSkinTresholds()
|
||||
{
|
||||
std::cout << "calibrating skin " << region_id << std::endl;
|
||||
return skin_detector.calibrateAndReturn(frame_out);
|
||||
}
|
||||
|
||||
void HandDetectRegion::setSkinTresholds(std::vector<int>& tresholds)
|
||||
{
|
||||
std::cout << "setting skin " << region_id << std::endl;
|
||||
skin_detector.setTresholds(tresholds);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
|
||||
#include "HandCalibrator.h"
|
||||
|
||||
#define MIN_HAND_SIZE 10000
|
||||
#define MIN_MENU_HAND_SIZE 10000
|
||||
#define MIN_GAME_HAND_SIZE 10000 // todo change
|
||||
namespace computervision
|
||||
{
|
||||
namespace handcalibration
|
||||
@@ -56,7 +57,7 @@ namespace computervision
|
||||
fingers_amount = amount;
|
||||
}
|
||||
|
||||
bool HandCalibrator::CheckIfHandPresent(cv::Mat input_image)
|
||||
bool HandCalibrator::CheckIfHandPresent(cv::Mat input_image, HandDetectionType type)
|
||||
{
|
||||
std::vector<std::vector<cv::Point>> points;
|
||||
cv::findContours(input_image, points, cv::RetrievalModes::RETR_LIST, cv::ContourApproximationModes::CHAIN_APPROX_SIMPLE);
|
||||
@@ -66,7 +67,11 @@ namespace computervision
|
||||
for (int p = 0; p < points.size(); p++)
|
||||
{
|
||||
int area = cv::contourArea(points[p]);
|
||||
if (area > MIN_HAND_SIZE) return true;
|
||||
if (type == handcalibration::HandDetectionType::MENU)
|
||||
if (area > MIN_MENU_HAND_SIZE) return true;
|
||||
|
||||
if (type == handcalibration::HandDetectionType::GAME)
|
||||
if (area > MIN_GAME_HAND_SIZE) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -7,11 +7,19 @@ namespace computervision
|
||||
{
|
||||
namespace handcalibration
|
||||
{
|
||||
enum class HandDetectionType
|
||||
{
|
||||
MENU,
|
||||
GAME
|
||||
};
|
||||
|
||||
class HandCalibrator
|
||||
{
|
||||
public:
|
||||
HandCalibrator();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief draws the text to show the status of the calibration on the image
|
||||
*
|
||||
@@ -45,7 +53,7 @@ namespace computervision
|
||||
*
|
||||
* @param input_image the input image to check.
|
||||
*/
|
||||
bool CheckIfHandPresent(cv::Mat input_image);
|
||||
bool CheckIfHandPresent(cv::Mat input_image, HandDetectionType type);
|
||||
|
||||
/**
|
||||
* @brief sets the amount of fingers that are currently detected.
|
||||
@@ -53,6 +61,7 @@ namespace computervision
|
||||
* @param amount the amount of fingers.
|
||||
*/
|
||||
void SetAmountOfFingers(int amount);
|
||||
|
||||
private:
|
||||
|
||||
bool background_calibrated;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#include "../renderEngine/renderer.h"
|
||||
#include "../shaders/entity_shader.h"
|
||||
#include "../toolbox/toolbox.h"
|
||||
#include <opencv2/core/base.hpp>
|
||||
#include "../computervision/HandDetectRegion.h"
|
||||
#include "../computervision/ObjectDetection.h"
|
||||
|
||||
|
||||
namespace scene
|
||||
@@ -23,6 +26,11 @@ namespace scene
|
||||
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
||||
std::vector<gui::GuiTexture*> guis;
|
||||
|
||||
std::vector<computervision::HandDetectRegion> regions;
|
||||
computervision::ObjectDetection objDetect;
|
||||
computervision::HandDetectRegion reg1("left", 20, 100, 150, 150);
|
||||
computervision::HandDetectRegion reg2("right", 200, 200, 150, 150);
|
||||
|
||||
|
||||
In_Game_Scene::In_Game_Scene()
|
||||
{
|
||||
@@ -105,6 +113,7 @@ namespace scene
|
||||
void scene::In_Game_Scene::update(GLFWwindow* window)
|
||||
{
|
||||
camera.Move(window);
|
||||
update_hand_detection();
|
||||
}
|
||||
|
||||
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
@@ -113,6 +122,26 @@ namespace scene
|
||||
{
|
||||
return_value = scene::Scenes::STOP;
|
||||
}
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS)
|
||||
{
|
||||
reg1.CalibrateBackground();
|
||||
reg2.CalibrateBackground();
|
||||
}
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
{
|
||||
std::vector<int> tresholds = reg1.CalculateSkinTresholds();
|
||||
reg2.setSkinTresholds(tresholds);
|
||||
}
|
||||
}
|
||||
|
||||
void scene::In_Game_Scene::update_hand_detection()
|
||||
{
|
||||
cv::Mat camera_frame = objDetect.ReadCamera();
|
||||
reg1.DetectHand(camera_frame);
|
||||
reg2.DetectHand(camera_frame);
|
||||
|
||||
cv::imshow("camera", camera_frame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace scene
|
||||
{
|
||||
private:
|
||||
scene::Scenes return_value = scene::Scenes::INGAME;
|
||||
void update_hand_detection();
|
||||
|
||||
public:
|
||||
In_Game_Scene();
|
||||
|
||||
@@ -8,15 +8,9 @@
|
||||
|
||||
namespace scene
|
||||
{
|
||||
std::vector<computervision::HandDetectRegion> regions;
|
||||
computervision::ObjectDetection objDetect;
|
||||
computervision::HandDetectRegion reg1("left",20,100,150,150);
|
||||
computervision::HandDetectRegion reg2("right",200,200,150,150);
|
||||
|
||||
scene::Scenes scene::Startup_Scene::start(GLFWwindow *window)
|
||||
{
|
||||
regions.push_back(reg1);
|
||||
regions.push_back(reg2);
|
||||
while (return_value == scene::Scenes::STARTUP)
|
||||
{
|
||||
render();
|
||||
@@ -36,30 +30,6 @@ namespace scene
|
||||
|
||||
void scene::Startup_Scene::update(GLFWwindow* window)
|
||||
{
|
||||
cv::Mat camera_frame = objDetect.ReadCamera();
|
||||
reg1.DetectHand(camera_frame);
|
||||
reg2.DetectHand(camera_frame);
|
||||
|
||||
cv::imshow("camera", camera_frame);
|
||||
|
||||
int key = cv::waitKey(1);
|
||||
|
||||
if (key == 98) // b, calibrate the background
|
||||
{
|
||||
for (int i = 0; i < regions.size(); i++)
|
||||
{
|
||||
regions[i].CalibrateBackground();
|
||||
}
|
||||
}
|
||||
else if (key == 115) // s, calibrate the skin color
|
||||
{
|
||||
std::vector<int> tresholds = regions[0].CalculateSkinTresholds();
|
||||
for (int i = 1; i < regions.size(); i++)
|
||||
{
|
||||
regions[i].setSkinTresholds(tresholds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user