[ADD] hand detection type enum

This commit is contained in:
Sem van der Hoeven
2021-06-08 13:38:47 +02:00
parent 1e55736615
commit cadee7d8e9
6 changed files with 53 additions and 48 deletions

View File

@@ -29,23 +29,11 @@ namespace computervision
// detect the hand contours
handMask = skin_detector.getSkinMask(foreground);
// count the amount of fingers and put the info on the matrix
//fingerCountDebug = finger_count.findFingersCount(handMask, frame_out);
//// get the amount of fingers
//int fingers_amount = finger_count.getAmountOfFingers();
// draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed.
DrawHandMask(&camera_frame);
//hand_calibrator.SetAmountOfFingers(fingers_amount);
//finger_count.DrawHandContours(camera_frame);
//hand_calibrator.DrawHandCalibrationText(camera_frame);
//imshow("camera", camera_frame);
imshow("output" + region_id, frame_out);
imshow("foreground" + region_id, foreground);
//imshow("output" + region_id, frame_out);
//imshow("foreground" + region_id, foreground);
imshow("handMask" + region_id, handMask);
/*imshow("handDetection", fingerCountDebug);*/
@@ -83,6 +71,7 @@ namespace computervision
void HandDetectRegion::CalibrateBackground()
{
std::cout << "calibrating background " << region_id << std::endl;
background_remover.calibrate(frame_out);
hand_calibrator.SetBackGroundCalibrated(true);
}
@@ -94,11 +83,13 @@ namespace computervision
std::vector<int> HandDetectRegion::CalculateSkinTresholds()
{
std::cout << "calibrating skin " << region_id << std::endl;
return skin_detector.calibrateAndReturn(frame_out);
}
void HandDetectRegion::setSkinTresholds(std::vector<int>& tresholds)
{
std::cout << "setting skin " << region_id << std::endl;
skin_detector.setTresholds(tresholds);
}

View File

@@ -1,7 +1,8 @@
#include "HandCalibrator.h"
#define MIN_HAND_SIZE 10000
#define MIN_MENU_HAND_SIZE 10000
#define MIN_GAME_HAND_SIZE 10000 // todo change
namespace computervision
{
namespace handcalibration
@@ -56,7 +57,7 @@ namespace computervision
fingers_amount = amount;
}
bool HandCalibrator::CheckIfHandPresent(cv::Mat input_image)
bool HandCalibrator::CheckIfHandPresent(cv::Mat input_image, HandDetectionType type)
{
std::vector<std::vector<cv::Point>> points;
cv::findContours(input_image, points, cv::RetrievalModes::RETR_LIST, cv::ContourApproximationModes::CHAIN_APPROX_SIMPLE);
@@ -66,7 +67,11 @@ namespace computervision
for (int p = 0; p < points.size(); p++)
{
int area = cv::contourArea(points[p]);
if (area > MIN_HAND_SIZE) return true;
if (type == handcalibration::HandDetectionType::MENU)
if (area > MIN_MENU_HAND_SIZE) return true;
if (type == handcalibration::HandDetectionType::GAME)
if (area > MIN_GAME_HAND_SIZE) return true;
}
return false;

View File

@@ -7,11 +7,19 @@ namespace computervision
{
namespace handcalibration
{
enum class HandDetectionType
{
MENU,
GAME
};
class HandCalibrator
{
public:
HandCalibrator();
/**
* @brief draws the text to show the status of the calibration on the image
*
@@ -45,7 +53,7 @@ namespace computervision
*
* @param input_image the input image to check.
*/
bool CheckIfHandPresent(cv::Mat input_image);
bool CheckIfHandPresent(cv::Mat input_image, HandDetectionType type);
/**
* @brief sets the amount of fingers that are currently detected.
@@ -53,6 +61,7 @@ namespace computervision
* @param amount the amount of fingers.
*/
void SetAmountOfFingers(int amount);
private:
bool background_calibrated;