[FEATURE] finished hand open/closed recognition

This commit is contained in:
Sem van der Hoeven
2021-05-25 14:49:04 +02:00
parent 3696e2eb30
commit 05ae8ee019
5 changed files with 28 additions and 9 deletions

View File

@@ -151,9 +151,16 @@ namespace computervision
drawVectorPoints(frame, filtered_finger_points, color_yellow, false);
putText(frame, to_string(filtered_finger_points.size()), center_bounding_rect, FONT_HERSHEY_PLAIN, 3, color_purple);
amount_of_fingers = filtered_finger_points.size();
return contours_image;
}
int FingerCount::getAmountOfFingers()
{
return amount_of_fingers;
}
double FingerCount::findPointsDistance(Point a, Point b) {
Point difference = a - b;
return sqrt(difference.ddot(difference));

View File

@@ -24,6 +24,13 @@ namespace computervision
*/
Mat findFingersCount(Mat input_image, Mat frame);
/**
* @brief gets the currently held-up finger count.
*
* @return the currently held-up finger count
*/
int getAmountOfFingers();
private:
// colors to use
Scalar color_blue;
@@ -34,6 +41,8 @@ namespace computervision
Scalar color_yellow;
Scalar color_purple;
int amount_of_fingers;
/**
* @brief finds the distance between 2 points.
*

View File

@@ -72,8 +72,9 @@ namespace computervision
return true;
}
bool ObjectDetection::detectHand(Mat inputFrame)
bool ObjectDetection::detectHand(Mat cameraFrame)
{
Mat inputFrame = generateHandMaskSquare(cameraFrame);
frameOut = inputFrame.clone();
skinDetector.drawSkinColorSampler(frameOut);
@@ -84,13 +85,17 @@ namespace computervision
handMask = skinDetector.getSkinMask(foreground);
fingerCountDebug = fingerCount.findFingersCount(handMask, frameOut);
int fingers_amount = fingerCount.getAmountOfFingers();
//backgroundRemover.calibrate(frame);
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);
imshow("camera", cameraFrame);
imshow("output", frameOut);
/* imshow("output", frameOut);
imshow("foreground", foreground);
imshow("handMask", handMask);
imshow("handDetection", fingerCountDebug);
imshow("handDetection", fingerCountDebug);*/
int key = waitKey(1);

View File

@@ -64,10 +64,10 @@ namespace computervision
/**
* @brief detects a hand based on the given hand mask input frame.
*
* @param inputFrame the input frame with only the hand
* @param inputFrame the input frame from the camera
* @return true if the webcam is connected, false if not.
*/
bool detectHand(cv::Mat inputFrame);
bool detectHand(cv::Mat cameraFrame);
/**
* @brief draws the hand mask rectangle on the given input matrix.

View File

@@ -87,9 +87,7 @@ int main(void)
render_engine::renderer::Render(entity, shader);
cameraFrame = objDetect.readCamera();
objDetect.detectHand(objDetect.generateHandMaskSquare(cameraFrame));
objDetect.drawHandMaskRect(&cameraFrame);
cv::imshow("camera",cameraFrame);
objDetect.detectHand(cameraFrame);
// Finish up