[ADD] added a on/off for hand detection in menu

you can switch between mouse and hand detection now
This commit is contained in:
Jasper
2021-06-08 11:14:07 +02:00
parent c94f798a9d
commit e7a9cda9dd
3 changed files with 37 additions and 32 deletions

View File

@@ -11,7 +11,7 @@
namespace computervision
{
cv::VideoCapture cap(1);
cv::VideoCapture cap(0);
cv::Mat img, imgGray, img2, img2Gray, img3, img4;

View File

@@ -76,12 +76,12 @@ namespace gui
{
double x_pos, y_pos;
glfwGetCursorPos(window, &x_pos, &y_pos);
std::cout << "Cursor pos in method: " << x_pos <<"::" << y_pos << std::endl;
//std::cout << "Cursor pos in method: " << x_pos <<"::" << y_pos << std::endl;
const float x_rel = (x_pos / SCALED_WIDTH / DEFAULT_WIDTH) * 2.0f - 1.0f;
const float y_rel = -((y_pos / SCALED_HEIGHT / DEFAULT_HEIGHT) * 2.0f - 1.0f);
std::cout << "x_rel And y_rel in method: " << x_rel << "::" << y_rel << std::endl;
//std::cout << "x_rel And y_rel in method: " << x_rel << "::" << y_rel << std::endl;
if (x_rel >= minXY.x && x_rel <= maxXY.x &&

View File

@@ -25,6 +25,7 @@ namespace scene
float item_number = 0;
bool hand_mode = false;
Startup_Scene::Startup_Scene() {
shaders::EntityShader shader;
@@ -120,41 +121,42 @@ namespace scene
if(new_button != NULL)
new_button->Update(window);
}
cameraFrame = objDetect.readCamera();
if (hand_mode) {
cameraFrame = objDetect.readCamera();
//Get hand state from camera
bool hand_detection = objDetect.detectHand(cameraFrame);
//Get hand state from camera
bool hand_detection = objDetect.detectHand(cameraFrame);
if (hand_detection)
{
hand_closed = false;
std::cout << "hand is opened" << std::endl;
if (hand_detection)
{
hand_closed = false;
std::cout << "hand is opened" << std::endl;
//Loop through menu items
chosen_item = GetMenuItem(true);
//Loop through menu items
chosen_item = GetMenuItem(true);
gui::Button* new_button = ConvertGuiTextureToButton(chosen_item);
if (new_button != NULL) {
const float x_pos = (chosen_item->position.x + 1.0)*WINDOW_WIDTH/2;
const float y_pos = (1.0 - chosen_item->position.y)*WINDOW_HEIGHT/2;
gui::Button* new_button = ConvertGuiTextureToButton(chosen_item);
if (new_button != NULL) {
const float x_pos = (chosen_item->position.x + 1.0) * WINDOW_WIDTH / 2;
const float y_pos = (1.0 - chosen_item->position.y) * WINDOW_HEIGHT / 2;
//Set cursor to location of selected menu_item
glfwSetCursorPos(window, x_pos, y_pos);
//Set cursor to location of selected menu_item
glfwSetCursorPos(window, x_pos, y_pos);
}
}
}
else if (!hand_detection)
{
std::cout << "hand is closed" << std::endl;
//Gets selected menu_item
chosen_item = GetMenuItem(false);
gui::Button* new_button = ConvertGuiTextureToButton(chosen_item);
if (new_button != NULL && !hand_closed) {
//Run function click
new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT);
hand_closed = true;
else if (!hand_detection)
{
std::cout << "hand is closed" << std::endl;
//Gets selected menu_item
chosen_item = GetMenuItem(false);
gui::Button* new_button = ConvertGuiTextureToButton(chosen_item);
if (new_button != NULL && !hand_closed) {
//Run function click
new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT);
hand_closed = true;
}
}
}
@@ -185,5 +187,8 @@ namespace scene
{
return_value = scene::Scenes::INGAME;
}
else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
hand_mode = !hand_mode;
}
}
}