[ADD] mask methods
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
|
|
||||||
|
#include <opencv2/videoio.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/video.hpp>
|
||||||
|
|
||||||
#include "ObjectDetection.h"
|
#include "ObjectDetection.h"
|
||||||
#include "BackgroundRemover.h"
|
#include "BackgroundRemover.h"
|
||||||
#include "SkinDetector.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()) {
|
if (!cap.isOpened()) {
|
||||||
cout << "Can't find camera!" << endl;
|
cout << "Can't find camera!" << endl;
|
||||||
@@ -72,10 +81,29 @@ namespace computervision
|
|||||||
imshow("threshold", img4);
|
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()
|
void ObjectDetection::detect()
|
||||||
{
|
{
|
||||||
int key = waitKey(1);
|
int key = waitKey(1);
|
||||||
|
|
||||||
if (key == 98) // b
|
if (key == 98) // b
|
||||||
backgroundRemover.calibrate(frame);
|
backgroundRemover.calibrate(frame);
|
||||||
else if (key == 115) // s
|
else if (key == 115) // s
|
||||||
|
|||||||
@@ -46,6 +46,21 @@ namespace computervision
|
|||||||
*/
|
*/
|
||||||
void detect();
|
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();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ int main(void)
|
|||||||
|
|
||||||
// set up object detection
|
// set up object detection
|
||||||
//objDetect.setup();
|
//objDetect.setup();
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
@@ -83,8 +84,7 @@ int main(void)
|
|||||||
|
|
||||||
render_engine::renderer::Render(entity, shader);
|
render_engine::renderer::Render(entity, shader);
|
||||||
|
|
||||||
//objDetect.setup();
|
objDetect.generateHandMaskSquare(objDetect.readCamera());
|
||||||
objDetect.calculateDifference();
|
|
||||||
|
|
||||||
// Finish up
|
// Finish up
|
||||||
shader.Stop();
|
shader.Stop();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace render_engine
|
|||||||
void Init(shaders::StaticShader& shader)
|
void Init(shaders::StaticShader& shader)
|
||||||
{
|
{
|
||||||
const glm::mat4 projectionMatrix =
|
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.Start();
|
||||||
shader.LoadProjectionMatrix(projectionMatrix);
|
shader.LoadProjectionMatrix(projectionMatrix);
|
||||||
|
|||||||
Reference in New Issue
Block a user