10 Commits

Author SHA1 Message Date
Lars
1f2258bc01 [ADD] skeleton code for different scenes 2021-05-25 15:52:41 +02:00
Sem van der Hoeven
ad4075a826 [EDIT] change window size to ints 2021-05-25 10:19:33 +02:00
Sem van der Hoeven
e50cd92a35 [ADD] some headers 2021-05-25 10:16:58 +02:00
Sem van der Hoeven
ff79c1525c Merge branch 'feature/objectdetection' into develop 2021-05-21 15:25:29 +02:00
Nathalie Seen
a7597c8d4f [ADD] comments to backgroundRemover 2021-05-21 15:24:06 +02:00
Sem van der Hoeven
5b4d9b624f Merge branch 'feature/objectdetection' into develop 2021-05-21 15:22:38 +02:00
Sem van der Hoeven
27aca98ea4 Merge branch 'feature/comments' into feature/objectdetection 2021-05-21 15:22:07 +02:00
Sem van der Hoeven
ca591dd427 [ADD] comments to fingercount 2021-05-21 15:21:03 +02:00
Sem van der Hoeven
acf24cab36 [ADD] comments to skindetector 2021-05-21 14:56:45 +02:00
Menno
01571d191f [FIXED] openCV included 2021-05-18 14:05:56 +02:00
15 changed files with 321 additions and 14 deletions

0
gameoverScene.cpp Normal file
View File

0
gameoverScene.h Normal file
View File

View File

@@ -11,15 +11,48 @@ using namespace std;
class BackgroundRemover { class BackgroundRemover {
public: public:
/**
* @brief constructor,
* create background variable and set calibrated to faslse
*
*/
BackgroundRemover(void); BackgroundRemover(void);
/**
* @brief sets the input image to a grayscale image
* sets calibrated to true
*
* @param input input the image that has to be calibrated
*/
void calibrate(Mat input); void calibrate(Mat input);
/**
* @brief Gets the mask of the foregorund of the input image
* and copies it to another image
*
* @param input The image from which the forground needs to be picked
* @return The image on which te foregroundmask is copied
*/
Mat getForeground(Mat input); Mat getForeground(Mat input);
private: private:
Mat background; Mat background;
bool calibrated = false; bool calibrated = false;
/**
* @brief Sets the image to grayscale and removes the background
*
* @param input The image from which the forground needs to be picked
* @return The mask of the foreground of the image
*/
Mat getForegroundMask(Mat input); Mat getForegroundMask(Mat input);
/**
* @brief makes everything on the background black
*
* @param input the image from which the background needs to be removed
* @param background the background of the image
*/
void removeBackground(Mat input, Mat background); void removeBackground(Mat input, Mat background);
}; };
} }

View File

@@ -15,9 +15,17 @@ namespace computervision
class FingerCount { class FingerCount {
public: public:
FingerCount(void); FingerCount(void);
/**
* @brief gets the amount of fingers that are held up.
*
* @param input_image the source image to find the fingers on. It should be a mask of a hand
* @param frame the frame to draw the resulting values on (how many fingers are held up etc)
* @return a new image with all the data drawn on it.
*/
Mat findFingersCount(Mat input_image, Mat frame); Mat findFingersCount(Mat input_image, Mat frame);
private: private:
// colors to use
Scalar color_blue; Scalar color_blue;
Scalar color_green; Scalar color_green;
Scalar color_red; Scalar color_red;
@@ -25,12 +33,78 @@ namespace computervision
Scalar color_white; Scalar color_white;
Scalar color_yellow; Scalar color_yellow;
Scalar color_purple; Scalar color_purple;
/**
* @brief finds the distance between 2 points.
*
* @param a the first point
* @param b the second point
* @return a double representing the distance
*/
double findPointsDistance(Point a, Point b); double findPointsDistance(Point a, Point b);
/**
* @brief compacts the given points on their medians.
* what it does is for each point, it checks if the distance to it's neighbour is greater than the
* max distance. If so, it just adds it to the list that is returned. If not, it calculates the
* median and adds it to the returned list
*
* @param points the points to compact
* @param max_neighbor_distance the maximum distance between points
* @return a vector with the points now compacted.
*/
vector<Point> compactOnNeighborhoodMedian(vector<Point> points, double max_neighbor_distance); vector<Point> compactOnNeighborhoodMedian(vector<Point> points, double max_neighbor_distance);
/**
* @brief finds the angle between 3 different points.
*
* @param a the first point
* @param b the second point
* @param c the third point
* @return the angle between the 3 points
*/
double findAngle(Point a, Point b, Point c); double findAngle(Point a, Point b, Point c);
/**
* @brief checks if the given points make up a finger.
*
* @param a the first point to check for
* @param b the second point to check for
* @param c the third point to check for
* @param limit_angle_inf the limit of the angle between 2 fingers
* @param limit_angle_sup the limit of the angle between a finger and a convex point
* @param palm_center the center of the palm
* @param distance_from_palm_tollerance the distance from the palm tolerance
* @return true if the points are a finger, false if not.
*/
bool isFinger(Point a, Point b, Point c, double limit_angle_inf, double limit_angle_sup, cv::Point palm_center, double distance_from_palm_tollerance); bool isFinger(Point a, Point b, Point c, double limit_angle_inf, double limit_angle_sup, cv::Point palm_center, double distance_from_palm_tollerance);
/**
* @brief finds the closest point to the given point that is in the given list.
*
* @param points the points to check for
* @param pivot the pivot to check against
* @return a vector containing the point that is closest
*/
vector<Point> findClosestOnX(vector<Point> points, Point pivot); vector<Point> findClosestOnX(vector<Point> points, Point pivot);
/**
* @brief finds the distance between the x coords of the points.
*
* @param a the first point
* @param b the second point
* @return the distance between the x values
*/
double findPointsDistanceOnX(Point a, Point b); double findPointsDistanceOnX(Point a, Point b);
/**
* @brief draws the points on the image.
*
* @param image the image to draw on
* @param points the points to draw
* @param color the color to draw them with
* @param with_numbers if the numbers should be drawn with the points
*/
void drawVectorPoints(Mat image, vector<Point> points, Scalar color, bool with_numbers); void drawVectorPoints(Mat image, vector<Point> points, Scalar color, bool with_numbers);
}; };
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include<opencv2\core.hpp> #include <opencv2\core.hpp>
#include <opencv2/imgcodecs.hpp> #include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <opencv2/imgproc/types_c.h> #include <opencv2/imgproc/types_c.h>
@@ -17,11 +17,31 @@ namespace computervision
public: public:
SkinDetector(void); SkinDetector(void);
/*
* @brief draws the positions in where the skin color will be sampled.
*
* @param input the input matrix to sample the skin color from
*/
void drawSkinColorSampler(Mat input); void drawSkinColorSampler(Mat input);
/*
* @brief calibrates the skin color detector with the given input frame
*
* @param input the input frame to calibrate from
*/
void calibrate(Mat input); void calibrate(Mat input);
/*
* @brief gets the mask for the hand
*
* @param input the input matrix to get the skin mask from
* @returns the skin mask in a new matrix
*/
Mat getSkinMask(Mat input); Mat getSkinMask(Mat input);
private: private:
// thresholds for hsv calculation
int hLowThreshold = 0; int hLowThreshold = 0;
int hHighThreshold = 0; int hHighThreshold = 0;
int sLowThreshold = 0; int sLowThreshold = 0;
@@ -29,11 +49,28 @@ namespace computervision
int vLowThreshold = 0; int vLowThreshold = 0;
int vHighThreshold = 0; int vHighThreshold = 0;
// wether or not the skindetector has calibrated yet.
bool calibrated = false; bool calibrated = false;
// rectangles that get drawn to show where the skin color will be sampled
Rect skinColorSamplerRectangle1, skinColorSamplerRectangle2; Rect skinColorSamplerRectangle1, skinColorSamplerRectangle2;
/*
* @brief calculates the skin tresholds for the given samples
*
* @param sample1 the first sample
* @param sample2 the second sample
*/
void calculateThresholds(Mat sample1, Mat sample2); void calculateThresholds(Mat sample1, Mat sample2);
void performOpening(Mat binaryImage, int structuralElementShapde, Point structuralElementSize);
/**
* @brief the opening. it generates the structuring element and performs the morphological transformations required to detect the hand.
* This needs to be done to get the skin mask.
*
* @param binaryImage the matrix to perform the opening on. This needs to be a binary image, so consisting of only 1's and 0's.
* @param structuralElementShape the shape to use for the kernel that is used with generating the structuring element
* @param structuralElementSize the size of the kernel that will be used with generating the structuring element.
*/
void performOpening(Mat binaryImage, int structuralElementShape, Point structuralElementSize);
}; };
} }

View File

@@ -4,6 +4,11 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.h"
#include <ostream> #include <ostream>
#include <map>
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/video.hpp>
#include "models/model.h" #include "models/model.h"
#include "renderEngine/loader.h" #include "renderEngine/loader.h"
@@ -12,6 +17,10 @@
#include "shaders/static_shader.h" #include "shaders/static_shader.h"
#include "toolbox/toolbox.h" #include "toolbox/toolbox.h"
#include "scenes/scene.h"
#include "scenes/startupScene.h"
#include "scenes/inGameScene.h"
#include "computervision/ObjectDetection.h" #include "computervision/ObjectDetection.h"
#pragma comment(lib, "glfw3.lib") #pragma comment(lib, "glfw3.lib")
@@ -22,6 +31,10 @@ static double UpdateDelta();
static GLFWwindow* window; static GLFWwindow* window;
//Scene management variables
std::map<Scenes, Scene*> scenes;
Scene* current_scene = nullptr;
int main(void) int main(void)
{ {
@@ -40,11 +53,14 @@ int main(void)
#pragma endregion #pragma endregion
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods) glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
if (key == GLFW_KEY_ESCAPE) current_scene->onKey(key, scancode, action, mods);
glfwSetWindowShouldClose(window, true); if (key == GLFW_KEY_ESCAPE)
}); glfwSetWindowShouldClose(window, true);
});
scenes[Scenes::STARTUP] = new StartupScene();
scenes[Scenes::INGAME] = new InGameScene();
models::RawModel raw_model = LoadObjModel("res/Tree.obj"); models::RawModel raw_model = LoadObjModel("res/Tree.obj");
models::ModelTexture texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") }; models::ModelTexture texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") };
@@ -57,12 +73,14 @@ int main(void)
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
// create object detection object instance
computervision::ObjectDetection objDetect; computervision::ObjectDetection objDetect;
// set up object detection // set up object detection
//objDetect.setup(); //objDetect.setup();
current_scene->start();
// Main game loop // Main game loop
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
@@ -70,15 +88,17 @@ int main(void)
const double delta = UpdateDelta(); const double delta = UpdateDelta();
entity.IncreaseRotation(glm::vec3(0, 1, 0)); entity.IncreaseRotation(glm::vec3(0, 1, 0));
camera.Move(window); camera.Move(window);
current_scene->update(window);
// Render // Render
render_engine::renderer::Prepare(); render_engine::renderer::Prepare();
shader.Start(); shader.Start();
shader.LoadViewMatrix(camera); shader.LoadViewMatrix(camera);
current_scene->render();
render_engine::renderer::Render(entity, shader); render_engine::renderer::Render(entity, shader);
objDetect.setup(); //objDetect.setup();
objDetect.calculateDifference();
// Finish up // Finish up
shader.Stop(); shader.Stop();
@@ -89,6 +109,7 @@ int main(void)
// Clean up // Clean up
shader.CleanUp(); shader.CleanUp();
render_engine::loader::CleanUp(); render_engine::loader::CleanUp();
current_scene->stop();
glfwTerminate(); glfwTerminate();
return 0; return 0;
} }

View File

@@ -0,0 +1,30 @@
#include "inGameScene.h"
#include <GLFW/glfw3.h>
void start()
{
}
void stop()
{
}
void render()
{
}
void update(GLFWwindow* window)
{
}
void onKey(int key, int scancode, int action, int mods)
{
/**
* misschien iets van als niet in settings dan hoeft alleen escape een knop zijn als reserve optie. Als wel in settings, dan heb je hetzelfde hoe je in het in het begin scherm hebt.
**/
}

15
src/scenes/inGameScene.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "scene.h"
class InGameScene : public Scene
{
private:
public:
virtual void start() override;
virtual void stop() override;
virtual void render() override;
virtual void update(GLFWwindow* window) override;
virtual void onKey(int key, int scancode, int action, int mods) override;
};

1
src/scenes/scene.cpp Normal file
View File

@@ -0,0 +1 @@
#include "scene.h"

23
src/scenes/scene.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include <GLFW/glfw3.h>
class Scene
{
public:
virtual void start() = 0;
virtual void stop() = 0;
virtual void render() = 0;
virtual void update(GLFWwindow* window) = 0;
virtual void onKey(int key, int scancode, int action, int mods) {};
};
enum class Scenes
{
STARTUP,
INGAME,
GAMEOVER,
SETTINGS,
CALIBRATION
};

View File

@@ -0,0 +1,31 @@
#include "startupScene.h"
#include <GLFW/glfw3.h>
void start()
{
}
void stop()
{
}
void render()
{
}
void update(GLFWwindow* window)
{
}
void onKey(int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_DOWN && action == GLFW_RELEASE)
{
//ideetje voor het scrollen door het menu heen
menuIndex = (menuIndex + 1) % 4;
}
}

15
src/scenes/startupScene.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "scene.h"
class StartupScene : public Scene
{
private:
int menuIndex;
public:
virtual void start() override;
virtual void stop() override;
virtual void render() override;
virtual void update(GLFWwindow* window) override;
virtual void onKey(int key, int scancode, int action, int mods) override;
};

View File

@@ -5,8 +5,8 @@
namespace toolbox namespace toolbox
{ {
#define WINDOW_WIDTH 1400.0f #define WINDOW_WIDTH 1400
#define WINDOW_HEIGT 800.0f #define WINDOW_HEIGT 800
glm::mat4 CreateModelMatrix(glm::vec3 translation, glm::vec3 rotation, float scale); glm::mat4 CreateModelMatrix(glm::vec3 translation, glm::vec3 rotation, float scale);

View File

@@ -19,6 +19,8 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\scenes\inGameScene.cpp" />
<ClCompile Include="src\scenes\scene.cpp" />
<ClCompile Include="src\computervision\FaceDetector.cpp" /> <ClCompile Include="src\computervision\FaceDetector.cpp" />
<ClCompile Include="src\computervision\ObjectDetection.cpp" /> <ClCompile Include="src\computervision\ObjectDetection.cpp" />
<ClCompile Include="src\computervision\SkinDetector.cpp" /> <ClCompile Include="src\computervision\SkinDetector.cpp" />
@@ -33,8 +35,11 @@
<ClCompile Include="src\shaders\shader_program.cpp" /> <ClCompile Include="src\shaders\shader_program.cpp" />
<ClCompile Include="src\shaders\static_shader.cpp" /> <ClCompile Include="src\shaders\static_shader.cpp" />
<ClCompile Include="src\toolbox\toolbox.cpp" /> <ClCompile Include="src\toolbox\toolbox.cpp" />
<ClCompile Include="src\scenes\startupScene.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\scenes\inGameScene.h" />
<ClInclude Include="src\scenes\scene.h" />
<ClInclude Include="src\computervision\FaceDetector.h" /> <ClInclude Include="src\computervision\FaceDetector.h" />
<ClInclude Include="src\computervision\FingerCount.h" /> <ClInclude Include="src\computervision\FingerCount.h" />
<ClInclude Include="src\computervision\BackgroundRemover.h" /> <ClInclude Include="src\computervision\BackgroundRemover.h" />
@@ -50,6 +55,7 @@
<ClInclude Include="src\shaders\static_shader.h" /> <ClInclude Include="src\shaders\static_shader.h" />
<ClInclude Include="src\stb_image.h" /> <ClInclude Include="src\stb_image.h" />
<ClInclude Include="src\toolbox\toolbox.h" /> <ClInclude Include="src\toolbox\toolbox.h" />
<ClInclude Include="src\scenes\startupScene.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" /> <Xml Include="res\haarcascade_frontalface_alt.xml" />
@@ -112,14 +118,16 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>C:\opencv\build\include;$(IncludePath)</IncludePath> <IncludePath>C:\opencv\build\include;$(IncludePath);C:\opencv\opencv\build\include</IncludePath>
<LibraryPath>C:\opencv\build\x64\vc15\lib;$(LibraryPath)</LibraryPath> <LibraryPath>C:\opencv\build\x64\vc15\lib;$(LibraryPath);C:\opencv\opencv\build\x64\vc15\lib</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);;C:\opencv\opencv\build\include</IncludePath>
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\opencv\opencv\build\x64\vc15\lib</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@@ -151,7 +159,7 @@
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.2\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.2\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_world452d.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>opencv_world452d.lib;%(AdditionalDependencies); opencv_world452.lib</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -192,6 +200,7 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.2\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.2\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies); opencv_world452.lib</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -57,6 +57,15 @@
<ClCompile Include="src\computervision\BackgroundRemover.cpp"> <ClCompile Include="src\computervision\BackgroundRemover.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\scenes\scene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\scenes\startupScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\scenes\inGameScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\entities\Camera.h"> <ClInclude Include="src\entities\Camera.h">
@@ -104,6 +113,15 @@
<ClInclude Include="src\computervision\BackgroundRemover.h"> <ClInclude Include="src\computervision\BackgroundRemover.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\scenes\scene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\startupScene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\inGameScene.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" /> <Xml Include="res\haarcascade_frontalface_alt.xml" />