From 27e99dd2ebc21dc075064a62ab03d13d59b640ca Mon Sep 17 00:00:00 2001 From: Kim Date: Tue, 1 Jun 2021 14:37:57 +0200 Subject: [PATCH 1/2] [ADD] Looping through array depending on open or closed hand --- src/computervision/MenuTest.cpp | 25 ++++++++++++ src/computervision/MenuTest.h | 18 +++++++++ src/computervision/ObjectDetection.cpp | 4 +- src/main.cpp | 53 +++++++++++++++++++++++++- wk2_fps.vcxproj | 2 + wk2_fps.vcxproj.filters | 6 +++ 6 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/computervision/MenuTest.cpp create mode 100644 src/computervision/MenuTest.h diff --git a/src/computervision/MenuTest.cpp b/src/computervision/MenuTest.cpp new file mode 100644 index 0000000..c5b90d1 --- /dev/null +++ b/src/computervision/MenuTest.cpp @@ -0,0 +1,25 @@ +#include "MenuTest.h" +#include + +namespace computervision +{ + int menu_item_array[4] = { 1, 2, 3, 4 }; + float item_number = 0; + + MenuTest::MenuTest(void) { + + } + + int MenuTest::GetMenuItem(bool hand_state) { + item_number += 0.20f; + + + int temp_item_number = item_number; + //If temp_item_number is equal to the size of the array, set item_number bac to zero to loop through the array again + if (temp_item_number == sizeof(menu_item_array) / sizeof(menu_item_array[0])) { + item_number = 0; + } + + return menu_item_array[temp_item_number]; + } +} \ No newline at end of file diff --git a/src/computervision/MenuTest.h b/src/computervision/MenuTest.h new file mode 100644 index 0000000..951a0a9 --- /dev/null +++ b/src/computervision/MenuTest.h @@ -0,0 +1,18 @@ + +namespace computervision +{ + class MenuTest { + public: + /** + * @brief Constructor for the class MenuTest, loads in array with menu items + * + */ + MenuTest(void); + /** + * @brief Returns the itemnumber in an array + * + * @param input_bool is either true or false, depending on the recognized hand gesture + */ + int GetMenuItem(bool input_bool); + }; +} \ No newline at end of file diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 62236d2..0cf97a5 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -59,10 +59,10 @@ namespace computervision putText(cameraFrame,hand_text, Point(10, 75), FONT_HERSHEY_PLAIN, 2.0, Scalar(255, 0, 255),3); imshow("camera", cameraFrame); - /* imshow("output", frameOut); + imshow("output", frameOut); imshow("foreground", foreground); imshow("handMask", handMask); - imshow("handDetection", fingerCountDebug);*/ + imshow("handDetection", fingerCountDebug); int key = waitKey(1); diff --git a/src/main.cpp b/src/main.cpp index 7bab3f9..5101b7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,8 @@ #include "stb_image.h" #include #include +#include +#include #include #include @@ -17,6 +19,7 @@ #include "shaders/static_shader.h" #include "toolbox/toolbox.h" +#include "computervision/MenuTest.h" #include "computervision/ObjectDetection.h" #pragma comment(lib, "glfw3.lib") @@ -26,7 +29,7 @@ static double UpdateDelta(); static GLFWwindow* window; - +int chosen_item = 0; int main(void) { @@ -87,8 +90,54 @@ int main(void) render_engine::renderer::Render(entity, shader); cameraFrame = objDetect.readCamera(); - objDetect.detectHand(cameraFrame); + ////////////////////////// KIMS SHIT //////////////////////////////////// + computervision::MenuTest menu_test; + + //Get hand state from camera + bool hand_detection = objDetect.detectHand(cameraFrame); + + if (hand_detection) + { + std::cout << "hand is opened" << std::endl; + + //Loop through menu items + chosen_item = menu_test.GetMenuItem(true); + + //For debug only, to see if chosen item is selected properly when hand is opened + std::cout << "chosen item: " << chosen_item << std::endl; + + } + else if (!hand_detection) + { + //for debug only, to see if the chosen item is selected properly when hand is closed + std::cout << "hand is closed" << std::endl; + //std::cout << "item to start: " << chosen_item << std::endl; + + //TODO link chosen item to the correct game states + switch (chosen_item) + { + case 1: + //Game state 0 + std::cout << "in case: " << chosen_item << std::endl; + break; + case 2: + //Game state 1 + std::cout << "in case: " << chosen_item << std::endl; + break; + case 3: + //Game state 2 + std::cout << "in case: " << chosen_item << std::endl; + break; + case 4: + //Game state 3 + std::cout << "in case: " << chosen_item << std::endl; + default: + break; + } + } + + ///////////////////////// END OF KIMS SHIT /////////////////////////////// // Finish up shader.Stop(); diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index fe5e71a..b160486 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -20,6 +20,7 @@ + @@ -38,6 +39,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index 54a06e5..503166c 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -57,6 +57,9 @@ Source Files + + Source Files + @@ -104,6 +107,9 @@ Header Files + + Header Files + From 623003a4f77bdcee1124c15b9d9057a53f3c607d Mon Sep 17 00:00:00 2001 From: Kim Date: Tue, 1 Jun 2021 14:40:26 +0200 Subject: [PATCH 2/2] [ADD] gitignore change --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9232336..488f5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -428,4 +428,6 @@ FodyWeavers.xsd **/docs/* **/doc/* +**/pose_iter_160000.caffemodel + # End of https://www.toptal.com/developers/gitignore/api/c++,visualstudio,visualstudiocode,opencv