[ADD] start of multiple squares
This commit is contained in:
10
src/computervision/HandDetectRegion.cpp
Normal file
10
src/computervision/HandDetectRegion.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include "HandDetectRegion.h"
|
||||
namespace computervision
|
||||
{
|
||||
HandDetectRegion::HandDetectRegion()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
22
src/computervision/HandDetectRegion.h
Normal file
22
src/computervision/HandDetectRegion.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
namespace computervision
|
||||
{
|
||||
class HandDetectRegion
|
||||
{
|
||||
public:
|
||||
HandDetectRegion();
|
||||
|
||||
cv::Mat GenerateHandMaskSquare();
|
||||
|
||||
void detectHand(cv::Mat camera_frame);
|
||||
|
||||
private:
|
||||
int start_x_pos;
|
||||
int start_y_pos;
|
||||
int height;
|
||||
int width;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -62,8 +62,9 @@ namespace computervision
|
||||
|
||||
// draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed.
|
||||
DrawHandMask(&camera_frame);
|
||||
string hand_text = fingers_amount > 0 ? "open" : "closed";
|
||||
putText(camera_frame, hand_text, Point(10, 75), FONT_HERSHEY_PLAIN, 2.0, Scalar(255, 0, 255), 3);
|
||||
|
||||
|
||||
hand_calibrator.SetAmountOfFingers(fingers_amount);
|
||||
finger_count.DrawHandContours(camera_frame);
|
||||
hand_calibrator.DrawHandCalibrationText(camera_frame);
|
||||
imshow("camera", camera_frame);
|
||||
|
||||
@@ -66,9 +66,27 @@ namespace computervision
|
||||
*/
|
||||
bool DrawHandMask(cv::Mat *input);
|
||||
|
||||
/**
|
||||
* @brief checks if the hand of the user is open.
|
||||
*
|
||||
* @return true if the hand is open, false if not.
|
||||
*/
|
||||
bool IsHandOpen();
|
||||
|
||||
|
||||
/**
|
||||
* @brief checks whether the hand is held within the detection square.
|
||||
*
|
||||
* @return true if the hand is in the detection square, false if not.
|
||||
*/
|
||||
bool IsHandPresent();
|
||||
|
||||
cv::VideoCapture GetCap();
|
||||
|
||||
private:
|
||||
bool is_hand_open;
|
||||
bool is_hand_present;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@ namespace computervision
|
||||
namespace handcalibration
|
||||
{
|
||||
|
||||
static bool background_calibrated;
|
||||
static bool skintone_calibrated;
|
||||
static bool hand_present;
|
||||
|
||||
HandCalibrator::HandCalibrator()
|
||||
{
|
||||
|
||||
@@ -22,12 +18,22 @@ namespace computervision
|
||||
cv::putText(output_frame, "Hand calibration", cv::Point(output_frame.cols / 2 - 100, 25), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(18, 219, 65), 2);
|
||||
cv::putText(output_frame, "press 'b' to calibrate background,then press 's' to calibrate skin tone", cv::Point(5, 35), cv::FONT_HERSHEY_PLAIN, 1.0, cv::Scalar(18, 219, 65), 1);
|
||||
|
||||
cv::rectangle(output_frame, cv::Rect(0, output_frame.rows - 80, 450, output_frame.cols), cv::Scalar(0, 0, 0), -1);
|
||||
|
||||
cv::putText(output_frame, "hand in frame:", cv::Point(5, output_frame.rows - 50), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 255, 0), 1);
|
||||
cv::rectangle(output_frame, cv::Rect(270, output_frame.rows - 70, 20, 20), hand_present ? cv::Scalar(0, 255, 0) : cv::Scalar(0,0,255), -1);
|
||||
cv::rectangle(output_frame, cv::Rect(420, output_frame.rows - 67, 15, 15), hand_present ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), -1);
|
||||
|
||||
cv::putText(output_frame, "background calibrated:", cv::Point(5, output_frame.rows - 30), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 255, 0), 1);
|
||||
cv::rectangle(output_frame, cv::Rect(420, output_frame.rows - 47, 15, 15), background_calibrated ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), -1);
|
||||
|
||||
cv::putText(output_frame, (background_calibrated ? "background calibrated" : "background not calibrated"), cv::Point(5, output_frame.rows-30), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 255, 0), 1);
|
||||
cv::putText(output_frame, (skintone_calibrated ? "skincolor calibrated" : "skincolor not calibrated"), cv::Point(5, output_frame.rows-10), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 255, 0), 1);
|
||||
cv::putText(output_frame, "skin color calibrated:", cv::Point(5, output_frame.rows - 10), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 255, 0), 1);
|
||||
cv::rectangle(output_frame, cv::Rect(420, output_frame.rows - 27, 15, 15), skintone_calibrated ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255), -1);
|
||||
|
||||
if (hand_present)
|
||||
{
|
||||
std::string hand_text = fingers_amount > 0 ? "open" : "closed";
|
||||
cv::putText(output_frame, hand_text, cv::Point(10, 75), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 0, 255), 3);
|
||||
}
|
||||
}
|
||||
|
||||
void HandCalibrator::SetSkinCalibration(bool val)
|
||||
@@ -45,6 +51,11 @@ namespace computervision
|
||||
hand_present = val;
|
||||
}
|
||||
|
||||
void HandCalibrator::SetAmountOfFingers(int amount)
|
||||
{
|
||||
fingers_amount = amount;
|
||||
}
|
||||
|
||||
bool HandCalibrator::CheckIfHandPresent(cv::Mat input_image)
|
||||
{
|
||||
std::vector<std::vector<cv::Point>> points;
|
||||
|
||||
@@ -47,6 +47,18 @@ namespace computervision
|
||||
*/
|
||||
bool CheckIfHandPresent(cv::Mat input_image);
|
||||
|
||||
/**
|
||||
* @brief sets the amount of fingers that are currently detected.
|
||||
*
|
||||
* @param amount the amount of fingers.
|
||||
*/
|
||||
void SetAmountOfFingers(int amount);
|
||||
private:
|
||||
|
||||
bool background_calibrated;
|
||||
bool skintone_calibrated;
|
||||
bool hand_present;
|
||||
int fingers_amount;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user