[FIX] only clicks ones when you close hand now

This commit is contained in:
Jasper
2021-06-04 16:41:16 +02:00
parent b3412e414e
commit aa4860eb48
3 changed files with 11 additions and 4 deletions

View File

@@ -59,10 +59,10 @@ namespace computervision
putText(cameraFrame,hand_text, Point(10, 75), FONT_HERSHEY_PLAIN, 2.0, Scalar(255, 0, 255),3); putText(cameraFrame,hand_text, Point(10, 75), FONT_HERSHEY_PLAIN, 2.0, Scalar(255, 0, 255),3);
imshow("camera", cameraFrame); imshow("camera", cameraFrame);
imshow("output", frameOut); //imshow("output", frameOut);
//imshow("foreground", foreground); //imshow("foreground", foreground);
//imshow("handMask", handMask); //imshow("handMask", handMask);
imshow("handDetection", fingerCountDebug); //imshow("handDetection", fingerCountDebug);
int key = waitKey(1); int key = waitKey(1);

View File

@@ -76,10 +76,14 @@ namespace gui
{ {
double x_pos, y_pos; double x_pos, y_pos;
glfwGetCursorPos(window, &x_pos, &y_pos); glfwGetCursorPos(window, &x_pos, &y_pos);
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 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); 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;
if (x_rel >= minXY.x && x_rel <= maxXY.x && if (x_rel >= minXY.x && x_rel <= maxXY.x &&
y_rel >= minXY.y && y_rel <= maxXY.y) y_rel >= minXY.y && y_rel <= maxXY.y)
{ {

View File

@@ -41,7 +41,6 @@ namespace scene
if (texture->GetType() == gui::GuiType::BUTTON) { if (texture->GetType() == gui::GuiType::BUTTON) {
gui::Button* button = (gui::Button*)texture; gui::Button* button = (gui::Button*)texture;
std::cout << button->clicked_texture << std::endl;
return button; return button;
} }
else { else {
@@ -110,6 +109,7 @@ namespace scene
computervision::ObjectDetection objDetect; computervision::ObjectDetection objDetect;
cv::Mat cameraFrame; cv::Mat cameraFrame;
gui::GuiTexture* chosen_item = NULL; gui::GuiTexture* chosen_item = NULL;
bool hand_closed = false;
while (return_value == scene::Scenes::STARTUP) while (return_value == scene::Scenes::STARTUP)
{ {
@@ -130,6 +130,8 @@ namespace scene
if (hand_detection) if (hand_detection)
{ {
hand_closed = false;
std::cout << "hand is opened" << std::endl; std::cout << "hand is opened" << std::endl;
//Loop through menu items //Loop through menu items
@@ -182,9 +184,10 @@ namespace scene
std::cout << chosen_item->texture << std::endl; std::cout << chosen_item->texture << std::endl;
gui::Button* new_button = ConvertGuiTextureToButton(chosen_item); gui::Button* new_button = ConvertGuiTextureToButton(chosen_item);
if (new_button != NULL) { if (new_button != NULL && !hand_closed) {
//Run function click //Run function click
new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT); new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT);
hand_closed = true;
} }
} }