From f1f1aac93db51e0a25f42729276895af2dd61df9 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 25 May 2021 15:54:02 +0200 Subject: [PATCH] [ADD] comments --- src/computervision/ObjectDetection.cpp | 27 ++++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index 4e19f2c..62236d2 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -24,9 +24,6 @@ namespace computervision FaceDetector faceDetector; FingerCount fingerCount; - - - ObjectDetection::ObjectDetection() { } @@ -41,16 +38,22 @@ namespace computervision Mat inputFrame = generateHandMaskSquare(cameraFrame); frameOut = inputFrame.clone(); + // detect skin color skinDetector.drawSkinColorSampler(frameOut); + // remove background from image foreground = backgroundRemover.getForeground(inputFrame); - //faceDetector.removeFaces(inputFrame, foreground); + // detect the hand contours handMask = skinDetector.getSkinMask(foreground); + + // count the amount of fingers and put the info on the matrix fingerCountDebug = fingerCount.findFingersCount(handMask, frameOut); + // get the amount of fingers int fingers_amount = fingerCount.getAmountOfFingers(); - //backgroundRemover.calibrate(frame); + + // draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed. drawHandMaskRect(&cameraFrame); string hand_text = fingers_amount > 0 ? "open" : "closed"; putText(cameraFrame,hand_text, Point(10, 75), FONT_HERSHEY_PLAIN, 2.0, Scalar(255, 0, 255),3); @@ -63,9 +66,9 @@ namespace computervision int key = waitKey(1); - if (key == 98) // b + if (key == 98) // b, calibrate the background backgroundRemover.calibrate(inputFrame); - else if (key == 115) // s + else if (key == 115) // s, calibrate the skin color skinDetector.calibrate(inputFrame); return fingers_amount > 0; @@ -113,16 +116,6 @@ namespace computervision return true; } - void ObjectDetection::detect() - { - int key = waitKey(1); - - if (key == 98) // b - backgroundRemover.calibrate(frame); - else if (key == 115) // s - skinDetector.calibrate(frame); - } - void ObjectDetection::showWebcam() { imshow("Webcam image", img);