Compare commits
4 Commits
feature/co
...
feature/ob
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7597c8d4f | ||
|
|
27aca98ea4 | ||
|
|
ca591dd427 | ||
|
|
acf24cab36 |
@@ -11,15 +11,48 @@ using namespace std;
|
|||||||
|
|
||||||
class BackgroundRemover {
|
class BackgroundRemover {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief constructor,
|
||||||
|
* create background variable and set calibrated to faslse
|
||||||
|
*
|
||||||
|
*/
|
||||||
BackgroundRemover(void);
|
BackgroundRemover(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sets the input image to a grayscale image
|
||||||
|
* sets calibrated to true
|
||||||
|
*
|
||||||
|
* @param input input the image that has to be calibrated
|
||||||
|
*/
|
||||||
void calibrate(Mat input);
|
void calibrate(Mat input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the mask of the foregorund of the input image
|
||||||
|
* and copies it to another image
|
||||||
|
*
|
||||||
|
* @param input The image from which the forground needs to be picked
|
||||||
|
* @return The image on which te foregroundmask is copied
|
||||||
|
*/
|
||||||
Mat getForeground(Mat input);
|
Mat getForeground(Mat input);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mat background;
|
Mat background;
|
||||||
bool calibrated = false;
|
bool calibrated = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the image to grayscale and removes the background
|
||||||
|
*
|
||||||
|
* @param input The image from which the forground needs to be picked
|
||||||
|
* @return The mask of the foreground of the image
|
||||||
|
*/
|
||||||
Mat getForegroundMask(Mat input);
|
Mat getForegroundMask(Mat input);
|
||||||
|
/**
|
||||||
|
* @brief makes everything on the background black
|
||||||
|
*
|
||||||
|
* @param input the image from which the background needs to be removed
|
||||||
|
* @param background the background of the image
|
||||||
|
*/
|
||||||
void removeBackground(Mat input, Mat background);
|
void removeBackground(Mat input, Mat background);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -15,9 +15,17 @@ namespace computervision
|
|||||||
class FingerCount {
|
class FingerCount {
|
||||||
public:
|
public:
|
||||||
FingerCount(void);
|
FingerCount(void);
|
||||||
|
/**
|
||||||
|
* @brief gets the amount of fingers that are held up.
|
||||||
|
*
|
||||||
|
* @param input_image the source image to find the fingers on. It should be a mask of a hand
|
||||||
|
* @param frame the frame to draw the resulting values on (how many fingers are held up etc)
|
||||||
|
* @return a new image with all the data drawn on it.
|
||||||
|
*/
|
||||||
Mat findFingersCount(Mat input_image, Mat frame);
|
Mat findFingersCount(Mat input_image, Mat frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// colors to use
|
||||||
Scalar color_blue;
|
Scalar color_blue;
|
||||||
Scalar color_green;
|
Scalar color_green;
|
||||||
Scalar color_red;
|
Scalar color_red;
|
||||||
@@ -25,12 +33,78 @@ namespace computervision
|
|||||||
Scalar color_white;
|
Scalar color_white;
|
||||||
Scalar color_yellow;
|
Scalar color_yellow;
|
||||||
Scalar color_purple;
|
Scalar color_purple;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief finds the distance between 2 points.
|
||||||
|
*
|
||||||
|
* @param a the first point
|
||||||
|
* @param b the second point
|
||||||
|
* @return a double representing the distance
|
||||||
|
*/
|
||||||
double findPointsDistance(Point a, Point b);
|
double findPointsDistance(Point a, Point b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief compacts the given points on their medians.
|
||||||
|
* what it does is for each point, it checks if the distance to it's neighbour is greater than the
|
||||||
|
* max distance. If so, it just adds it to the list that is returned. If not, it calculates the
|
||||||
|
* median and adds it to the returned list
|
||||||
|
*
|
||||||
|
* @param points the points to compact
|
||||||
|
* @param max_neighbor_distance the maximum distance between points
|
||||||
|
* @return a vector with the points now compacted.
|
||||||
|
*/
|
||||||
vector<Point> compactOnNeighborhoodMedian(vector<Point> points, double max_neighbor_distance);
|
vector<Point> compactOnNeighborhoodMedian(vector<Point> points, double max_neighbor_distance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief finds the angle between 3 different points.
|
||||||
|
*
|
||||||
|
* @param a the first point
|
||||||
|
* @param b the second point
|
||||||
|
* @param c the third point
|
||||||
|
* @return the angle between the 3 points
|
||||||
|
*/
|
||||||
double findAngle(Point a, Point b, Point c);
|
double findAngle(Point a, Point b, Point c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief checks if the given points make up a finger.
|
||||||
|
*
|
||||||
|
* @param a the first point to check for
|
||||||
|
* @param b the second point to check for
|
||||||
|
* @param c the third point to check for
|
||||||
|
* @param limit_angle_inf the limit of the angle between 2 fingers
|
||||||
|
* @param limit_angle_sup the limit of the angle between a finger and a convex point
|
||||||
|
* @param palm_center the center of the palm
|
||||||
|
* @param distance_from_palm_tollerance the distance from the palm tolerance
|
||||||
|
* @return true if the points are a finger, false if not.
|
||||||
|
*/
|
||||||
bool isFinger(Point a, Point b, Point c, double limit_angle_inf, double limit_angle_sup, cv::Point palm_center, double distance_from_palm_tollerance);
|
bool isFinger(Point a, Point b, Point c, double limit_angle_inf, double limit_angle_sup, cv::Point palm_center, double distance_from_palm_tollerance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief finds the closest point to the given point that is in the given list.
|
||||||
|
*
|
||||||
|
* @param points the points to check for
|
||||||
|
* @param pivot the pivot to check against
|
||||||
|
* @return a vector containing the point that is closest
|
||||||
|
*/
|
||||||
vector<Point> findClosestOnX(vector<Point> points, Point pivot);
|
vector<Point> findClosestOnX(vector<Point> points, Point pivot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief finds the distance between the x coords of the points.
|
||||||
|
*
|
||||||
|
* @param a the first point
|
||||||
|
* @param b the second point
|
||||||
|
* @return the distance between the x values
|
||||||
|
*/
|
||||||
double findPointsDistanceOnX(Point a, Point b);
|
double findPointsDistanceOnX(Point a, Point b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief draws the points on the image.
|
||||||
|
*
|
||||||
|
* @param image the image to draw on
|
||||||
|
* @param points the points to draw
|
||||||
|
* @param color the color to draw them with
|
||||||
|
* @param with_numbers if the numbers should be drawn with the points
|
||||||
|
*/
|
||||||
void drawVectorPoints(Mat image, vector<Point> points, Scalar color, bool with_numbers);
|
void drawVectorPoints(Mat image, vector<Point> points, Scalar color, bool with_numbers);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<opencv2\core.hpp>
|
#include <opencv2\core.hpp>
|
||||||
#include <opencv2/imgcodecs.hpp>
|
#include <opencv2/imgcodecs.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <opencv2/imgproc/types_c.h>
|
#include <opencv2/imgproc/types_c.h>
|
||||||
@@ -17,11 +17,31 @@ namespace computervision
|
|||||||
public:
|
public:
|
||||||
SkinDetector(void);
|
SkinDetector(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief draws the positions in where the skin color will be sampled.
|
||||||
|
*
|
||||||
|
* @param input the input matrix to sample the skin color from
|
||||||
|
*/
|
||||||
void drawSkinColorSampler(Mat input);
|
void drawSkinColorSampler(Mat input);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief calibrates the skin color detector with the given input frame
|
||||||
|
*
|
||||||
|
* @param input the input frame to calibrate from
|
||||||
|
*/
|
||||||
void calibrate(Mat input);
|
void calibrate(Mat input);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief gets the mask for the hand
|
||||||
|
*
|
||||||
|
* @param input the input matrix to get the skin mask from
|
||||||
|
* @returns the skin mask in a new matrix
|
||||||
|
*/
|
||||||
Mat getSkinMask(Mat input);
|
Mat getSkinMask(Mat input);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
// thresholds for hsv calculation
|
||||||
int hLowThreshold = 0;
|
int hLowThreshold = 0;
|
||||||
int hHighThreshold = 0;
|
int hHighThreshold = 0;
|
||||||
int sLowThreshold = 0;
|
int sLowThreshold = 0;
|
||||||
@@ -29,11 +49,28 @@ namespace computervision
|
|||||||
int vLowThreshold = 0;
|
int vLowThreshold = 0;
|
||||||
int vHighThreshold = 0;
|
int vHighThreshold = 0;
|
||||||
|
|
||||||
|
// wether or not the skindetector has calibrated yet.
|
||||||
bool calibrated = false;
|
bool calibrated = false;
|
||||||
|
|
||||||
|
// rectangles that get drawn to show where the skin color will be sampled
|
||||||
Rect skinColorSamplerRectangle1, skinColorSamplerRectangle2;
|
Rect skinColorSamplerRectangle1, skinColorSamplerRectangle2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief calculates the skin tresholds for the given samples
|
||||||
|
*
|
||||||
|
* @param sample1 the first sample
|
||||||
|
* @param sample2 the second sample
|
||||||
|
*/
|
||||||
void calculateThresholds(Mat sample1, Mat sample2);
|
void calculateThresholds(Mat sample1, Mat sample2);
|
||||||
void performOpening(Mat binaryImage, int structuralElementShapde, Point structuralElementSize);
|
|
||||||
|
/**
|
||||||
|
* @brief the opening. it generates the structuring element and performs the morphological transformations required to detect the hand.
|
||||||
|
* This needs to be done to get the skin mask.
|
||||||
|
*
|
||||||
|
* @param binaryImage the matrix to perform the opening on. This needs to be a binary image, so consisting of only 1's and 0's.
|
||||||
|
* @param structuralElementShape the shape to use for the kernel that is used with generating the structuring element
|
||||||
|
* @param structuralElementSize the size of the kernel that will be used with generating the structuring element.
|
||||||
|
*/
|
||||||
|
void performOpening(Mat binaryImage, int structuralElementShape, Point structuralElementSize);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,7 @@ int main(void)
|
|||||||
|
|
||||||
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
|
// create object detection object instance
|
||||||
computervision::ObjectDetection objDetect;
|
computervision::ObjectDetection objDetect;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user