From afd3e00ddb0e44c6584f70b72e607819fac45391 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 8 Jun 2021 11:03:22 +0200 Subject: [PATCH] [ADD] contour of hand in calibration screen --- src/computervision/FingerCount.cpp | 11 +++++++---- src/computervision/FingerCount.h | 10 ++++++++++ src/computervision/ObjectDetection.cpp | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/computervision/FingerCount.cpp b/src/computervision/FingerCount.cpp index 590e2a2..bdd1938 100644 --- a/src/computervision/FingerCount.cpp +++ b/src/computervision/FingerCount.cpp @@ -14,6 +14,7 @@ namespace computervision { + FingerCount::FingerCount(void) { color_blue = Scalar(255, 0, 0); color_green = Scalar(0, 255, 0); @@ -35,9 +36,6 @@ namespace computervision if (input_image.channels() != 1) return contours_image; - vector> contours; - vector hierarchy; - findContours(input_image, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); // we need at least one contour to work @@ -45,7 +43,7 @@ namespace computervision return contours_image; // find the biggest contour (let's suppose it's our hand) - int biggest_contour_index = -1; + biggest_contour_index = -1; double biggest_area = 0.0; for (int i = 0; i < contours.size(); i++) { @@ -156,6 +154,11 @@ namespace computervision return contours_image; } + void FingerCount::DrawHandContours(Mat& image) + { + drawContours(image, contours, biggest_contour_index, color_green, 2, 8, hierarchy); + } + int FingerCount::getAmountOfFingers() { return amount_of_fingers; diff --git a/src/computervision/FingerCount.h b/src/computervision/FingerCount.h index 3319150..4b31c92 100644 --- a/src/computervision/FingerCount.h +++ b/src/computervision/FingerCount.h @@ -31,7 +31,15 @@ namespace computervision */ int getAmountOfFingers(); + void DrawHandContours(Mat& image); + private: + + int biggest_contour_index; + vector> contours; + vector hierarchy; + + // colors to use Scalar color_blue; Scalar color_green; @@ -115,5 +123,7 @@ namespace computervision * @param with_numbers if the numbers should be drawn with the points */ void drawVectorPoints(Mat image, vector points, Scalar color, bool with_numbers); + + }; } \ No newline at end of file diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index ba8030d..1d36826 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -64,7 +64,7 @@ namespace computervision 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); - + finger_count.DrawHandContours(camera_frame); hand_calibrator.DrawHandCalibrationText(camera_frame); imshow("camera", camera_frame);