[ADD] start for object detection

This commit is contained in:
Sem van der Hoeven
2021-05-21 11:19:17 +02:00
parent ca0f7546bf
commit ab3b0c296a
5 changed files with 82 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#include "ObjectDetection.h"
namespace computervision
{
cv::VideoCapture cap(0);
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
ObjectDetection::ObjectDetection()
{
}
void ObjectDetection::readWebcam()
{
cap.read(img);
}
void ObjectDetection::calculateDifference()
{
cap.read(img);
cap.read(img2);
cv::cvtColor(img, imgGray, cv::COLOR_RGBA2GRAY);
cv::cvtColor(img2, img2Gray, cv::COLOR_RGBA2GRAY);
cv::absdiff(imgGray, img2Gray, img3);
cv::threshold(img3, img4, 50, 170, cv::THRESH_BINARY);
imshow("threshold", img4);
}
void ObjectDetection::showWebcam()
{
imshow("Webcam image", img);
}
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
namespace computervision
{
class ObjectDetection
{
private:
public:
ObjectDetection();
void readWebcam();
void showWebcam();
void calculateDifference();
};
}

View File

@@ -12,6 +12,8 @@
#include "shaders/static_shader.h"
#include "toolbox/toolbox.h"
#include "computervision/ObjectDetection.h"
#pragma comment(lib, "glfw3.lib")
#pragma comment(lib, "glew32s.lib")
#pragma comment(lib, "opengl32.lib")
@@ -54,6 +56,12 @@ int main(void)
render_engine::renderer::Init(shader);
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
computervision::ObjectDetection objDetect;
// Main game loop
while (!glfwWindowShouldClose(window))
@@ -69,6 +77,8 @@ int main(void)
shader.LoadViewMatrix(camera);
render_engine::renderer::Render(entity, shader);
objDetect.calculateDifference();
// Finish up
shader.Stop();

View File

@@ -19,6 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
<ClCompile Include="src\entities\camera.cpp" />
<ClCompile Include="src\entities\entity.cpp" />
<ClCompile Include="src\main.cpp" />
@@ -30,6 +31,7 @@
<ClCompile Include="src\toolbox\toolbox.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\computervision\ObjectDetection.h" />
<ClInclude Include="src\entities\camera.h" />
<ClInclude Include="src\entities\entity.h" />
<ClInclude Include="src\models\model.h" />

View File

@@ -42,6 +42,9 @@
<ClCompile Include="src\toolbox\toolbox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\computervision\ObjectDetection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\entities\Camera.h">
@@ -74,5 +77,8 @@
<ClInclude Include="src\toolbox\toolbox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\computervision\ObjectDetection.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>