[FEATURE] finished hand open/closed recognition
This commit is contained in:
@@ -151,9 +151,16 @@ namespace computervision
|
|||||||
drawVectorPoints(frame, filtered_finger_points, color_yellow, false);
|
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);
|
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;
|
return contours_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FingerCount::getAmountOfFingers()
|
||||||
|
{
|
||||||
|
return amount_of_fingers;
|
||||||
|
}
|
||||||
|
|
||||||
double FingerCount::findPointsDistance(Point a, Point b) {
|
double FingerCount::findPointsDistance(Point a, Point b) {
|
||||||
Point difference = a - b;
|
Point difference = a - b;
|
||||||
return sqrt(difference.ddot(difference));
|
return sqrt(difference.ddot(difference));
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ namespace computervision
|
|||||||
*/
|
*/
|
||||||
Mat findFingersCount(Mat input_image, Mat frame);
|
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:
|
private:
|
||||||
// colors to use
|
// colors to use
|
||||||
Scalar color_blue;
|
Scalar color_blue;
|
||||||
@@ -34,6 +41,8 @@ namespace computervision
|
|||||||
Scalar color_yellow;
|
Scalar color_yellow;
|
||||||
Scalar color_purple;
|
Scalar color_purple;
|
||||||
|
|
||||||
|
int amount_of_fingers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief finds the distance between 2 points.
|
* @brief finds the distance between 2 points.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -72,8 +72,9 @@ namespace computervision
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectDetection::detectHand(Mat inputFrame)
|
bool ObjectDetection::detectHand(Mat cameraFrame)
|
||||||
{
|
{
|
||||||
|
Mat inputFrame = generateHandMaskSquare(cameraFrame);
|
||||||
frameOut = inputFrame.clone();
|
frameOut = inputFrame.clone();
|
||||||
|
|
||||||
skinDetector.drawSkinColorSampler(frameOut);
|
skinDetector.drawSkinColorSampler(frameOut);
|
||||||
@@ -84,13 +85,17 @@ namespace computervision
|
|||||||
handMask = skinDetector.getSkinMask(foreground);
|
handMask = skinDetector.getSkinMask(foreground);
|
||||||
fingerCountDebug = fingerCount.findFingersCount(handMask, frameOut);
|
fingerCountDebug = fingerCount.findFingersCount(handMask, frameOut);
|
||||||
|
|
||||||
|
int fingers_amount = fingerCount.getAmountOfFingers();
|
||||||
//backgroundRemover.calibrate(frame);
|
//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("foreground", foreground);
|
||||||
imshow("handMask", handMask);
|
imshow("handMask", handMask);
|
||||||
imshow("handDetection", fingerCountDebug);
|
imshow("handDetection", fingerCountDebug);*/
|
||||||
|
|
||||||
int key = waitKey(1);
|
int key = waitKey(1);
|
||||||
|
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ namespace computervision
|
|||||||
/**
|
/**
|
||||||
* @brief detects a hand based on the given hand mask input frame.
|
* @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.
|
* @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.
|
* @brief draws the hand mask rectangle on the given input matrix.
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ int main(void)
|
|||||||
render_engine::renderer::Render(entity, shader);
|
render_engine::renderer::Render(entity, shader);
|
||||||
|
|
||||||
cameraFrame = objDetect.readCamera();
|
cameraFrame = objDetect.readCamera();
|
||||||
objDetect.detectHand(objDetect.generateHandMaskSquare(cameraFrame));
|
objDetect.detectHand(cameraFrame);
|
||||||
objDetect.drawHandMaskRect(&cameraFrame);
|
|
||||||
cv::imshow("camera",cameraFrame);
|
|
||||||
|
|
||||||
|
|
||||||
// Finish up
|
// Finish up
|
||||||
|
|||||||
Reference in New Issue
Block a user