[ADD] mask methods

This commit is contained in:
Sem van der Hoeven
2021-05-25 13:31:25 +02:00
parent ad4075a826
commit 276aa1a449
4 changed files with 48 additions and 5 deletions

View File

@@ -1,4 +1,8 @@
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#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

View File

@@ -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();
};

View File

@@ -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();

View File

@@ -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);