[EDIT] added base for hand detection

This commit is contained in:
Sem van der Hoeven
2021-05-21 13:23:33 +02:00
parent 27a09aeca4
commit 1811bf51a4
9 changed files with 24401 additions and 20 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -42,7 +42,7 @@ namespace computervision
}
void BackgroundRemover::removeBackground(Mat input, Mat background) {
int thresholdOffset = 10;
int thresholdOffset = 25;
for (int i = 0; i < input.rows; i++) {
for (int j = 0; j < input.cols; j++) {

View File

@@ -8,7 +8,7 @@ namespace computervision
{
Rect getFaceRect(Mat input);
String faceClassifierFileName = "../res/haarcascade_frontalface_alt.xml";
String faceClassifierFileName = "res/haarcascade_frontalface_alt.xml";
CascadeClassifier faceCascadeClassifier;
FaceDetector::FaceDetector(void) {
@@ -23,7 +23,7 @@ namespace computervision
cvtColor(input, frameGray, CV_BGR2GRAY);
equalizeHist(frameGray, frameGray);
faceCascadeClassifier.detectMultiScale(frameGray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(120, 120));
faceCascadeClassifier.detectMultiScale(frameGray, faces, 1.1, 2, 0 | 2, Size(120, 120)); // HAAR_SCALE_IMAGE is 2
for (size_t i = 0; i < faces.size(); i++) {
rectangle(
@@ -43,7 +43,7 @@ namespace computervision
cvtColor(input, inputGray, CV_BGR2GRAY);
equalizeHist(inputGray, inputGray);
faceCascadeClassifier.detectMultiScale(inputGray, faceRectangles, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(120, 120));
faceCascadeClassifier.detectMultiScale(inputGray, faceRectangles, 1.1, 2, 0 | 2, Size(120, 120)); // HAAR_SCALE_IMAGE is 2
if (faceRectangles.size() > 0)
return faceRectangles[0];

View File

@@ -1,7 +1,9 @@
#pragma once
#include"opencv2\opencv.hpp"
#include <opencv2\imgproc\types_c.h>
#include <opencv2/objdetect/objdetect_c.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/objdetect.hpp>
#include <opencv2/core.hpp>
#include <opencv2/objdetect/objdetect.hpp>
/*
Author: Pierfrancesco Soffritti https://github.com/PierfrancescoSoffritti
*/

View File

@@ -1,11 +1,4 @@
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include "ObjectDetection.h"
#include "ObjectDetection.h"
#include "BackgroundRemover.h"
#include "SkinDetector.h"
@@ -29,7 +22,7 @@ namespace computervision
{
}
bool ObjectDetection::Init()
bool ObjectDetection::setup()
{
if (!cap.isOpened()) {
cout << "Can't find camera!" << endl;
@@ -45,6 +38,22 @@ namespace computervision
faceDetector.removeFaces(frame, foreground);
handMask = skinDetector.getSkinMask(foreground);
fingerCountDebug = fingerCount.findFingersCount(handMask, frameOut);
//backgroundRemover.calibrate(frame);
imshow("output", frameOut);
imshow("foreground", foreground);
imshow("handMask", handMask);
imshow("handDetection", fingerCountDebug);
int key = waitKey(1);
if (key == 98) // b
backgroundRemover.calibrate(frame);
else if (key == 115) // s
skinDetector.calibrate(frame);
return true;
}
@@ -68,6 +77,16 @@ namespace computervision
imshow("threshold", img4);
}
void ObjectDetection::detect()
{
int key = waitKey(1);
if (key == 115)
skinDetector.calibrate(frame);
}
void ObjectDetection::showWebcam()
{
imshow("Webcam image", img);

View File

@@ -9,6 +9,7 @@
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
namespace computervision
{
class ObjectDetection
@@ -17,10 +18,11 @@ namespace computervision
public:
ObjectDetection();
bool Init();
bool setup();
void readWebcam();
void showWebcam();
void calculateDifference();
void detect();
};

View File

@@ -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")
@@ -58,8 +60,8 @@ int main(void)
computervision::ObjectDetection objDetect;
// set up object detection
//objDetect.setup();
// Main game loop
while (!glfwWindowShouldClose(window))
@@ -76,7 +78,7 @@ int main(void)
render_engine::renderer::Render(entity, shader);
objDetect.calculateDifference();
objDetect.setup();
// Finish up
shader.Stop();

View File

@@ -51,6 +51,9 @@
<ClInclude Include="src\stb_image.h" />
<ClInclude Include="src\toolbox\toolbox.h" />
</ItemGroup>
<ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{A7ECF1BE-DB22-4BF7-BFF6-E3BF72691EE6}</ProjectGuid>

View File

@@ -105,4 +105,7 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Xml Include="res\haarcascade_frontalface_alt.xml" />
</ItemGroup>
</Project>