diff --git a/src/computervision/HandDetectRegion.cpp b/src/computervision/HandDetectRegion.cpp new file mode 100644 index 0000000..0b012db --- /dev/null +++ b/src/computervision/HandDetectRegion.cpp @@ -0,0 +1,10 @@ + +#include "HandDetectRegion.h" +namespace computervision +{ + HandDetectRegion::HandDetectRegion() + { + } + + +} diff --git a/src/computervision/HandDetectRegion.h b/src/computervision/HandDetectRegion.h new file mode 100644 index 0000000..4bdadf2 --- /dev/null +++ b/src/computervision/HandDetectRegion.h @@ -0,0 +1,22 @@ +#pragma once + +#include +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; + }; + +} diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 1d36826..530e474 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -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); diff --git a/src/computervision/ObjectDetection.h b/src/computervision/ObjectDetection.h index 1b65e1f..92fc335 100644 --- a/src/computervision/ObjectDetection.h +++ b/src/computervision/ObjectDetection.h @@ -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; + }; diff --git a/src/computervision/calibration/HandCalibrator.cpp b/src/computervision/calibration/HandCalibrator.cpp index 9d91a46..36c64ea 100644 --- a/src/computervision/calibration/HandCalibrator.cpp +++ b/src/computervision/calibration/HandCalibrator.cpp @@ -7,10 +7,6 @@ namespace computervision namespace handcalibration { - static bool background_calibrated; - static bool skintone_calibrated; - static bool hand_present; - HandCalibrator::HandCalibrator() { @@ -18,16 +14,26 @@ namespace computervision void HandCalibrator::DrawHandCalibrationText(cv::Mat& output_frame) { - cv::rectangle(output_frame,cv::Rect(0, 0, output_frame.cols, 40),cv::Scalar(0,0,0),-1); - 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::rectangle(output_frame, cv::Rect(0, 0, output_frame.cols, 40), cv::Scalar(0, 0, 0), -1); + 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> points; diff --git a/src/computervision/calibration/HandCalibrator.h b/src/computervision/calibration/HandCalibrator.h index f402adb..9b2f7ae 100644 --- a/src/computervision/calibration/HandCalibrator.h +++ b/src/computervision/calibration/HandCalibrator.h @@ -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; }; }