[ADD] start for object detection
This commit is contained in:
36
src/computervision/ObjectDetection.cpp
Normal file
36
src/computervision/ObjectDetection.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
28
src/computervision/ObjectDetection.h
Normal file
28
src/computervision/ObjectDetection.h
Normal 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();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
10
src/main.cpp
10
src/main.cpp
@@ -12,6 +12,8 @@
|
|||||||
#include "shaders/static_shader.h"
|
#include "shaders/static_shader.h"
|
||||||
#include "toolbox/toolbox.h"
|
#include "toolbox/toolbox.h"
|
||||||
|
|
||||||
|
#include "computervision/ObjectDetection.h"
|
||||||
|
|
||||||
#pragma comment(lib, "glfw3.lib")
|
#pragma comment(lib, "glfw3.lib")
|
||||||
#pragma comment(lib, "glew32s.lib")
|
#pragma comment(lib, "glew32s.lib")
|
||||||
#pragma comment(lib, "opengl32.lib")
|
#pragma comment(lib, "opengl32.lib")
|
||||||
@@ -55,6 +57,12 @@ 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));
|
||||||
|
|
||||||
|
computervision::ObjectDetection objDetect;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
@@ -70,6 +78,8 @@ int main(void)
|
|||||||
|
|
||||||
render_engine::renderer::Render(entity, shader);
|
render_engine::renderer::Render(entity, shader);
|
||||||
|
|
||||||
|
objDetect.calculateDifference();
|
||||||
|
|
||||||
// Finish up
|
// Finish up
|
||||||
shader.Stop();
|
shader.Stop();
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
|
||||||
<ClCompile Include="src\entities\camera.cpp" />
|
<ClCompile Include="src\entities\camera.cpp" />
|
||||||
<ClCompile Include="src\entities\entity.cpp" />
|
<ClCompile Include="src\entities\entity.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
<ClCompile Include="src\toolbox\toolbox.cpp" />
|
<ClCompile Include="src\toolbox\toolbox.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="src\computervision\ObjectDetection.h" />
|
||||||
<ClInclude Include="src\entities\camera.h" />
|
<ClInclude Include="src\entities\camera.h" />
|
||||||
<ClInclude Include="src\entities\entity.h" />
|
<ClInclude Include="src\entities\entity.h" />
|
||||||
<ClInclude Include="src\models\model.h" />
|
<ClInclude Include="src\models\model.h" />
|
||||||
|
|||||||
@@ -42,6 +42,9 @@
|
|||||||
<ClCompile Include="src\toolbox\toolbox.cpp">
|
<ClCompile Include="src\toolbox\toolbox.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\computervision\ObjectDetection.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\entities\Camera.h">
|
<ClInclude Include="src\entities\Camera.h">
|
||||||
@@ -74,5 +77,8 @@
|
|||||||
<ClInclude Include="src\toolbox\toolbox.h">
|
<ClInclude Include="src\toolbox\toolbox.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\computervision\ObjectDetection.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user