Skip to content
/ Hand-Detection Public template

Fingers & Motion Tracking Library ๐Ÿ––

Notifications You must be signed in to change notification settings

leonma333/Hand-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Hand-Detection

opencv c++ mit license

HandDetection is a light weighted C++ library to track hands using OpenCV.

Requriments

C++ (11 or above) and OpenCV (2 or above) installed.

How does it work?

The library using background subtraction method to detect hand(s) to do the tracking. The pictures below show an instance of the frame and foreground from the library.

Current Frame Foreground Frame
hand detection frame hand detection foreground

With clear and clean foreground images, accurate analysis can be done. For example, finger tip locations, palm center, movement, etc, endless things can be acheived.

Compare to pure skin color detection, it is more adaptable, as it does not need to be calibrated to adapt to different skin colors and surrounding. Therefore, as long as the background is stationary, the background subtraction will always work like a charm.

Features

HandDetection class so far provides the following functions:

  • start() - start the detector
  • stop() - stop the detector
  • getFrame() - get the current frame from webcam
  • getBackground() - get the current background frame by using background subtraction
  • getForeground() - get the current foreground frame by using background subtraction
  • getFingers() - get the number of fingers are currently up
  • getDirection() - get the current hand moving direction (beta)

main.cpp already shown an example usage of the HandDetection class, but the following code snippet is provided to give a more comprehensive example:

#include <thread>
#include "hand_detection.h"

using namespace std;

int main(int argc, char *argv[]) {
    HandDetection handDetector;
    
    // always put start() in another thread
    thread t(&HandDetection::start, &handDetector);
    
    namedWindow("Frame");
    namedWindow("Foreground");
    namedWindow("Background");
    
    while(1) {
        imshow("Frame", handDetector.getFrame());
        imshow("Foreground", handDetector.getForeground());
        imshow("Background", handDetector.getBackground());
        
        cout << "Finger Number: " << handDetector.getFingers() << endl;
        cout << "Moving Ditection: " << handDetector.getDirection() << endl;
        
        if (waitKey(10) >= 0) {
            handDetector.stop();
            break;
        }
    }
    
    t.join();
    
    return 0;
}

Enjoy ใƒฝ(^o^)ใƒŽ

About

Fingers & Motion Tracking Library ๐Ÿ––

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published