From ab3b0c296a7d56064a3249d31d4c71a835d767cb Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Fri, 21 May 2021 11:19:17 +0200 Subject: [PATCH] [ADD] start for object detection --- src/computervision/ObjectDetection.cpp | 36 ++++++++++++++++++++++++++ src/computervision/ObjectDetection.h | 28 ++++++++++++++++++++ src/main.cpp | 10 +++++++ wk2_fps.vcxproj | 2 ++ wk2_fps.vcxproj.filters | 6 +++++ 5 files changed, 82 insertions(+) create mode 100644 src/computervision/ObjectDetection.cpp create mode 100644 src/computervision/ObjectDetection.h diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp new file mode 100644 index 0000000..deeb2c6 --- /dev/null +++ b/src/computervision/ObjectDetection.cpp @@ -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); + } + + +} \ No newline at end of file diff --git a/src/computervision/ObjectDetection.h b/src/computervision/ObjectDetection.h new file mode 100644 index 0000000..dca7180 --- /dev/null +++ b/src/computervision/ObjectDetection.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace computervision +{ + class ObjectDetection + { + private: + + public: + ObjectDetection(); + void readWebcam(); + void showWebcam(); + void calculateDifference(); + + }; + + +} + diff --git a/src/main.cpp b/src/main.cpp index 316baec..f17272d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 8de3076..786b98b 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -19,6 +19,7 @@ + @@ -30,6 +31,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index d3370e0..f005835 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -42,6 +42,9 @@ Source Files + + Source Files + @@ -74,5 +77,8 @@ Header Files + + Header Files + \ No newline at end of file