diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 5f16929..47c8c80 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -1,4 +1,8 @@ +#include +#include +#include + #include "ObjectDetection.h" #include "BackgroundRemover.h" #include "SkinDetector.h" @@ -22,7 +26,12 @@ namespace computervision { } - bool ObjectDetection::setup() + cv::Mat ObjectDetection::readCamera() { + cap.read(img); + return img; + } + + bool ObjectDetection::setup() { if (!cap.isOpened()) { cout << "Can't find camera!" << endl; @@ -72,10 +81,29 @@ namespace computervision imshow("threshold", img4); } + + cv::Mat ObjectDetection::generateHandMaskSquare(cv::Mat img) + { + + cv::Mat mask = cv::Mat::zeros(img.size(), img.type()); + cv::Mat dstImg = cv::Mat::zeros(img.size(), img.type()); + + cv::rectangle(mask, Rect(0, img.rows * 0.2, img.cols / 3, img.cols / 3), Scalar(255, 255, 255), -1); + //cv::circle(mask, cv::Point(mask.cols / 2, mask.rows / 2), 50, cv::Scalar(255, 0, 0), -1, 8, 0); + + + img.copyTo(dstImg, mask); + + rectangle(img, Rect(0, img.rows * 0.2, img.cols / 3, img.cols / 3), Scalar(0, 255, 255, 255)); + + return dstImg; + + } + void ObjectDetection::detect() { int key = waitKey(1); - + if (key == 98) // b backgroundRemover.calibrate(frame); else if (key == 115) // s diff --git a/src/computervision/ObjectDetection.h b/src/computervision/ObjectDetection.h index 4344ed7..2c74d44 100644 --- a/src/computervision/ObjectDetection.h +++ b/src/computervision/ObjectDetection.h @@ -46,6 +46,21 @@ namespace computervision */ void detect(); + /** + * @brief generates the square that will hold the mask in which the hand will be detected. + * + * @param img the current camear frame + * @return a matrix containing the mask + */ + cv::Mat generateHandMaskSquare(cv::Mat img); + + /** + * @brief reads the camera and returns it in a matrix. + * + * @return the camera frame in a matrix + */ + cv::Mat readCamera(); + }; diff --git a/src/main.cpp b/src/main.cpp index 53cb0a4..f4a17a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,6 +67,7 @@ int main(void) // set up object detection //objDetect.setup(); + // Main game loop while (!glfwWindowShouldClose(window)) @@ -83,8 +84,7 @@ int main(void) render_engine::renderer::Render(entity, shader); - //objDetect.setup(); - objDetect.calculateDifference(); + objDetect.generateHandMaskSquare(objDetect.readCamera()); // Finish up shader.Stop(); diff --git a/src/renderEngine/Renderer.cpp b/src/renderEngine/Renderer.cpp index b1d2564..87e421c 100644 --- a/src/renderEngine/Renderer.cpp +++ b/src/renderEngine/Renderer.cpp @@ -18,7 +18,7 @@ namespace render_engine void Init(shaders::StaticShader& shader) { const glm::mat4 projectionMatrix = - glm::perspective(glm::radians(FOV), (WINDOW_WIDTH / WINDOW_HEIGT), NEAR_PLANE, FAR_PLANE); + glm::perspective(glm::radians(FOV), (float)(WINDOW_WIDTH / WINDOW_HEIGT), NEAR_PLANE, FAR_PLANE); shader.Start(); shader.LoadProjectionMatrix(projectionMatrix);