[FIX] detecting hand when its just a finger or hair
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define MIN_HAND_SIZE 10000
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
@@ -10,9 +11,16 @@ namespace computervision
|
||||
std::vector<std::vector<cv::Point>> points;
|
||||
cv::Mat imgCont;
|
||||
cv::findContours(inputImage, points, cv::RetrievalModes::RETR_LIST, cv::ContourApproximationModes::CHAIN_APPROX_SIMPLE);
|
||||
bool hand_present = points.size() > 0;
|
||||
std::cout << (hand_present ? "hey a hand!" : "damn no hand") << std::endl;
|
||||
return hand_present;
|
||||
|
||||
if (points.size() == 0) return false;
|
||||
|
||||
for (int p = 0; p < points.size(); p++)
|
||||
{
|
||||
int area = cv::contourArea(points[p]);
|
||||
if (area > MIN_HAND_SIZE) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace computervision
|
||||
return cap;
|
||||
}
|
||||
|
||||
bool ObjectDetection::detectHand(Mat cameraFrame)
|
||||
bool ObjectDetection::detectHand(Mat cameraFrame, bool& hand_present)
|
||||
{
|
||||
Mat inputFrame = generateHandMaskSquare(cameraFrame);
|
||||
frameOut = inputFrame.clone();
|
||||
@@ -72,7 +72,7 @@ namespace computervision
|
||||
//imshow("handMask", handMask);
|
||||
//imshow("handDetection", fingerCountDebug);
|
||||
|
||||
check_if_hand_present(handMask);
|
||||
hand_present = check_if_hand_present(handMask);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,9 +54,10 @@ namespace computervision
|
||||
* @brief detects a hand based on the given hand mask input frame.
|
||||
*
|
||||
* @param inputFrame the input frame from the camera
|
||||
* @param hand_present boolean that will hold true if the hand is detected, false if not.
|
||||
* @return true if hand is open, false if hand is closed
|
||||
*/
|
||||
bool detectHand(cv::Mat cameraFrame);
|
||||
bool detectHand(cv::Mat cameraFrame, bool& hand_present);
|
||||
|
||||
/**
|
||||
* @brief draws the hand mask rectangle on the given input matrix.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <map>
|
||||
#include "startup_Scene.h"
|
||||
#include "../computervision/ObjectDetection.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace scene
|
||||
{
|
||||
@@ -29,7 +30,9 @@ namespace scene
|
||||
|
||||
void scene::Startup_Scene::update(GLFWwindow* window)
|
||||
{
|
||||
objDetect.detectHand(objDetect.readCamera());
|
||||
bool hand_detected = false;
|
||||
objDetect.detectHand(objDetect.readCamera(),hand_detected);
|
||||
if (hand_detected) std::cout << "there's a hand!" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user