[ADD] Looping through array depending on open or closed hand

This commit is contained in:
Kim
2021-06-01 14:37:57 +02:00
parent f1f1aac93d
commit 27e99dd2eb
6 changed files with 104 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
#include "MenuTest.h"
#include <iostream>
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];
}
}

View File

@@ -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);
};
}

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);
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);

View File

@@ -5,6 +5,8 @@
#include "stb_image.h"
#include <ostream>
#include <stdlib.h>
#include <iostream>
#include <Windows.h>
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
@@ -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();

View File

@@ -20,6 +20,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\computervision\FaceDetector.cpp" />
<ClCompile Include="src\computervision\MenuTest.cpp" />
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
<ClCompile Include="src\computervision\SkinDetector.cpp" />
<ClCompile Include="src\computervision\FingerCount.cpp" />
@@ -38,6 +39,7 @@
<ClInclude Include="src\computervision\FaceDetector.h" />
<ClInclude Include="src\computervision\FingerCount.h" />
<ClInclude Include="src\computervision\BackgroundRemover.h" />
<ClInclude Include="src\computervision\MenuTest.h" />
<ClInclude Include="src\computervision\SkinDetector.h" />
<ClInclude Include="src\computervision\ObjectDetection.h" />
<ClInclude Include="src\entities\camera.h" />

View File

@@ -57,6 +57,9 @@
<ClCompile Include="src\computervision\BackgroundRemover.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\computervision\MenuTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\entities\Camera.h">
@@ -104,6 +107,9 @@
<ClInclude Include="src\computervision\BackgroundRemover.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\computervision\MenuTest.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" />