Compare commits
20 Commits
feature/co
...
BUGGED/pos
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
612adf6e9b | ||
|
|
25c99abb72 | ||
|
|
9d80cddbd1 | ||
|
|
40529f84b3 | ||
|
|
a68c6a57bf | ||
|
|
078a6ce66d | ||
|
|
f1f1aac93d | ||
|
|
563f465e2c | ||
|
|
05ae8ee019 | ||
|
|
3696e2eb30 | ||
|
|
276aa1a449 | ||
|
|
ad4075a826 | ||
|
|
e50cd92a35 | ||
|
|
ff79c1525c | ||
|
|
a7597c8d4f | ||
|
|
5b4d9b624f | ||
|
|
27aca98ea4 | ||
|
|
ca591dd427 | ||
|
|
acf24cab36 | ||
|
|
01571d191f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -428,4 +428,6 @@ FodyWeavers.xsd
|
||||
**/docs/*
|
||||
**/doc/*
|
||||
|
||||
**/pose_iter_160000.caffemodel
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/c++,visualstudio,visualstudiocode,opencv
|
||||
|
||||
2976
res/pose/coco/pose_deploy_linevec.prototxt
Normal file
2976
res/pose/coco/pose_deploy_linevec.prototxt
Normal file
File diff suppressed because it is too large
Load Diff
2081
res/pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt
Normal file
2081
res/pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,15 +11,48 @@ using namespace std;
|
||||
|
||||
class BackgroundRemover {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief constructor,
|
||||
* create background variable and set calibrated to faslse
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
private:
|
||||
Mat background;
|
||||
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);
|
||||
/**
|
||||
* @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);
|
||||
};
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -15,9 +15,24 @@ namespace computervision
|
||||
class FingerCount {
|
||||
public:
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief gets the currently held-up finger count.
|
||||
*
|
||||
* @return the currently held-up finger count
|
||||
*/
|
||||
int getAmountOfFingers();
|
||||
|
||||
private:
|
||||
// colors to use
|
||||
Scalar color_blue;
|
||||
Scalar color_green;
|
||||
Scalar color_red;
|
||||
@@ -25,12 +40,80 @@ namespace computervision
|
||||
Scalar color_white;
|
||||
Scalar color_yellow;
|
||||
Scalar color_purple;
|
||||
|
||||
int amount_of_fingers;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
};
|
||||
}
|
||||
@@ -1,47 +1,66 @@
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#include "ObjectDetection.h"
|
||||
#include "BackgroundRemover.h"
|
||||
#include "SkinDetector.h"
|
||||
#include "FaceDetector.h"
|
||||
#include "FingerCount.h"
|
||||
#include "VideoCapture.h"
|
||||
|
||||
using namespace videocapture;
|
||||
namespace computervision
|
||||
{
|
||||
cv::VideoCapture cap(0);
|
||||
|
||||
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
|
||||
|
||||
int handMaskStartXPos, handMaskStartYPos, handMaskWidth, handMaskHeight;
|
||||
bool handMaskGenerated = false;
|
||||
|
||||
Mat frame, frameOut, handMask, foreground, fingerCountDebug;
|
||||
BackgroundRemover backgroundRemover;
|
||||
SkinDetector skinDetector;
|
||||
FaceDetector faceDetector;
|
||||
FingerCount fingerCount;
|
||||
|
||||
|
||||
ObjectDetection::ObjectDetection()
|
||||
{
|
||||
}
|
||||
|
||||
bool ObjectDetection::setup()
|
||||
cv::Mat ObjectDetection::readCamera() {
|
||||
/*videocapture::getMutex()->lock();
|
||||
|
||||
videocapture::getCap().read(img);
|
||||
|
||||
videocapture::getMutex()->unlock();*/
|
||||
img = videocapture::readFrame();
|
||||
return img;
|
||||
}
|
||||
|
||||
bool ObjectDetection::detectHand(Mat cameraFrame)
|
||||
{
|
||||
if (!cap.isOpened()) {
|
||||
cout << "Can't find camera!" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
cap.read(frame);
|
||||
frameOut = frame.clone();
|
||||
Mat inputFrame = generateHandMaskSquare(cameraFrame);
|
||||
frameOut = inputFrame.clone();
|
||||
|
||||
// detect skin color
|
||||
skinDetector.drawSkinColorSampler(frameOut);
|
||||
|
||||
foreground = backgroundRemover.getForeground(frame);
|
||||
// remove background from image
|
||||
foreground = backgroundRemover.getForeground(inputFrame);
|
||||
|
||||
faceDetector.removeFaces(frame, foreground);
|
||||
// detect the hand contours
|
||||
handMask = skinDetector.getSkinMask(foreground);
|
||||
|
||||
// count the amount of fingers and put the info on the matrix
|
||||
fingerCountDebug = fingerCount.findFingersCount(handMask, frameOut);
|
||||
|
||||
//backgroundRemover.calibrate(frame);
|
||||
// get the amount of fingers
|
||||
int fingers_amount = fingerCount.getAmountOfFingers();
|
||||
|
||||
// draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed.
|
||||
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("foreground", foreground);
|
||||
@@ -50,18 +69,23 @@ namespace computervision
|
||||
|
||||
int key = waitKey(1);
|
||||
|
||||
if (key == 98) // b
|
||||
backgroundRemover.calibrate(frame);
|
||||
else if (key == 115) // s
|
||||
skinDetector.calibrate(frame);
|
||||
if (key == 98) // b, calibrate the background
|
||||
backgroundRemover.calibrate(inputFrame);
|
||||
else if (key == 115) // s, calibrate the skin color
|
||||
skinDetector.calibrate(inputFrame);
|
||||
|
||||
return true;
|
||||
return fingers_amount > 0;
|
||||
}
|
||||
|
||||
void ObjectDetection::calculateDifference()
|
||||
{
|
||||
cap.read(img);
|
||||
cap.read(img2);
|
||||
//videocapture::getMutex()->lock();
|
||||
//videocapture::getCap().read(img);
|
||||
//videocapture::getCap().read(img2);
|
||||
//videocapture::getMutex()->unlock()
|
||||
|
||||
img = videocapture::readFrame();
|
||||
img2 = videocapture::readFrame();
|
||||
|
||||
cv::cvtColor(img, imgGray, cv::COLOR_RGBA2GRAY);
|
||||
cv::cvtColor(img2, img2Gray, cv::COLOR_RGBA2GRAY);
|
||||
@@ -72,14 +96,32 @@ namespace computervision
|
||||
imshow("threshold", img4);
|
||||
}
|
||||
|
||||
void ObjectDetection::detect()
|
||||
{
|
||||
int key = waitKey(1);
|
||||
|
||||
if (key == 98) // b
|
||||
backgroundRemover.calibrate(frame);
|
||||
else if (key == 115) // s
|
||||
skinDetector.calibrate(frame);
|
||||
cv::Mat ObjectDetection::generateHandMaskSquare(cv::Mat img)
|
||||
{
|
||||
handMaskStartXPos = 20;
|
||||
handMaskStartYPos = img.rows / 5;
|
||||
handMaskWidth = img.cols / 3;
|
||||
handMaskHeight = img.cols / 3;
|
||||
|
||||
|
||||
cv::Mat mask = cv::Mat::zeros(img.size(), img.type());
|
||||
cv::Mat dstImg = cv::Mat::zeros(img.size(), img.type());
|
||||
|
||||
cv::rectangle(mask, Rect(handMaskStartXPos, handMaskStartYPos, handMaskWidth, handMaskHeight), Scalar(255, 255, 255), -1);
|
||||
|
||||
img.copyTo(dstImg, mask);
|
||||
|
||||
handMaskGenerated = true;
|
||||
return dstImg;
|
||||
|
||||
}
|
||||
|
||||
bool ObjectDetection::drawHandMaskRect(cv::Mat* input)
|
||||
{
|
||||
if (!handMaskGenerated) return false;
|
||||
rectangle(*input, Rect(handMaskStartXPos, handMaskStartYPos, handMaskWidth, handMaskHeight), Scalar(255, 255, 255));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ObjectDetection::showWebcam()
|
||||
|
||||
@@ -22,13 +22,7 @@ namespace computervision
|
||||
*
|
||||
*/
|
||||
ObjectDetection();
|
||||
/**
|
||||
* @brief Initializes the object detection, captures a frame and modifies it
|
||||
* so it is ready to use for object detection
|
||||
*
|
||||
* @return return true if webcam is connected, returns false if it isn't
|
||||
*/
|
||||
bool setup();
|
||||
|
||||
/**
|
||||
* @brief Displays an image of the current webcam-footage
|
||||
*
|
||||
@@ -40,11 +34,38 @@ namespace computervision
|
||||
*
|
||||
*/
|
||||
void calculateDifference();
|
||||
|
||||
/**
|
||||
* @brief Listens for keypresses and handles them
|
||||
* @brief generates the square that will hold the mask in which the hand will be detected.
|
||||
*
|
||||
* @param img the current camear frame
|
||||
* @return a matrix containing the mask
|
||||
*/
|
||||
void detect();
|
||||
cv::Mat generateHandMaskSquare(cv::Mat img);
|
||||
|
||||
/**
|
||||
* @brief reads the camera and returns it in a matrix.
|
||||
*
|
||||
* @return the camera frame in a matrix
|
||||
*/
|
||||
cv::Mat readCamera();
|
||||
|
||||
/**
|
||||
* @brief detects a hand based on the given hand mask input frame.
|
||||
*
|
||||
* @param inputFrame the input frame from the camera
|
||||
* @return true if hand is open, false if hand is closed
|
||||
*/
|
||||
bool detectHand(cv::Mat cameraFrame);
|
||||
|
||||
/**
|
||||
* @brief draws the hand mask rectangle on the given input matrix.
|
||||
*
|
||||
* @param input the input matrix to draw the rectangle on
|
||||
*/
|
||||
bool drawHandMaskRect(cv::Mat *input);
|
||||
|
||||
cv::VideoCapture getCap();
|
||||
|
||||
};
|
||||
|
||||
|
||||
111
src/computervision/OpenPoseVideo.cpp
Normal file
111
src/computervision/OpenPoseVideo.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#include "OpenPoseVideo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::dnn;
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
#define MPI
|
||||
|
||||
#ifdef MPI
|
||||
const int POSE_PAIRS[7][2] =
|
||||
{
|
||||
{0,1}, {1,2}, {2,3},
|
||||
{3,4}, {1,5}, {5,6},
|
||||
{6,7}
|
||||
};
|
||||
|
||||
string protoFile = "res/pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt";
|
||||
string weightsFile = "res/pose/mpi/pose_iter_160000.caffemodel";
|
||||
|
||||
int nPoints = 8;
|
||||
#endif
|
||||
|
||||
#ifdef COCO
|
||||
const int POSE_PAIRS[17][2] =
|
||||
{
|
||||
{1,2}, {1,5}, {2,3},
|
||||
{3,4}, {5,6}, {6,7},
|
||||
{1,8}, {8,9}, {9,10},
|
||||
{1,11}, {11,12}, {12,13},
|
||||
{1,0}, {0,14},
|
||||
{14,16}, {0,15}, {15,17}
|
||||
};
|
||||
|
||||
string protoFile = "pose/coco/pose_deploy_linevec.prototxt";
|
||||
string weightsFile = "pose/coco/pose_iter_440000.caffemodel";
|
||||
|
||||
int nPoints = 18;
|
||||
#endif
|
||||
Net net;
|
||||
int inWidth = 368;
|
||||
int inHeight = 368;
|
||||
float thresh = 0.01;
|
||||
|
||||
void OpenPoseVideo::setup() {
|
||||
net = readNetFromCaffe(protoFile, weightsFile);
|
||||
}
|
||||
|
||||
cv::Mat OpenPoseVideo::getBlobFromImage(cv::Mat inputImage)
|
||||
{
|
||||
Mat frame;
|
||||
int frameWidth = inputImage.size().width;
|
||||
int frameHeight = inputImage.size().height;
|
||||
|
||||
double t = (double)cv::getTickCount();
|
||||
std::cout << "reading input image and blob" << std::endl;
|
||||
|
||||
frame = inputImage.clone();
|
||||
Mat inpBlob = blobFromImage(frame, 1.0 / 255, Size(inWidth, inHeight), Scalar(0, 0, 0), false, false);
|
||||
return inpBlob;
|
||||
}
|
||||
|
||||
void OpenPoseVideo::movementSkeleton(Mat inputImage, Mat inpBlob, std::function<void(std::vector<Point>)> f) {
|
||||
std::cout << "movement skeleton start" << std::endl;
|
||||
|
||||
int frameWidth = inputImage.size().width;
|
||||
int frameHeight = inputImage.size().height;
|
||||
|
||||
std::cout << "done reading image and blob" << std::endl;
|
||||
|
||||
net.setInput(inpBlob);
|
||||
|
||||
std::cout << "done setting input to net" << std::endl;
|
||||
Mat output = net.forward();
|
||||
|
||||
|
||||
int H = output.size[2];
|
||||
int W = output.size[3];
|
||||
|
||||
std::cout << "about to find position of boxy parts" << std::endl;
|
||||
// find the position of the body parts
|
||||
vector<Point> points(nPoints);
|
||||
for (int n = 0; n < nPoints; n++)
|
||||
{
|
||||
// Probability map of corresponding body's part.
|
||||
Mat probMap(H, W, CV_32F, output.ptr(0, n));
|
||||
|
||||
Point2f p(-1, -1);
|
||||
Point maxLoc;
|
||||
double prob;
|
||||
minMaxLoc(probMap, 0, &prob, 0, &maxLoc);
|
||||
if (prob > thresh)
|
||||
{
|
||||
p = maxLoc;
|
||||
p.x *= (float)frameWidth / W;
|
||||
p.y *= (float)frameHeight / H;
|
||||
|
||||
/*circle(frame, cv::Point((int)p.x, (int)p.y), 8, Scalar(0, 255, 255), -1);
|
||||
cv::putText(frame, cv::format("%d", n), cv::Point((int)p.x, (int)p.y), cv::FONT_HERSHEY_COMPLEX, 1.1, cv::Scalar(0, 0, 255), 2);*/
|
||||
}
|
||||
points[n] = p;
|
||||
}
|
||||
|
||||
//cv::putText(frame, cv::format("time taken = %.2f sec", t), cv::Point(50, 50), cv::FONT_HERSHEY_COMPLEX, .8, cv::Scalar(255, 50, 0), 2);
|
||||
// imshow("Output-Keypoints", frameCopy);
|
||||
/*imshow("Output-Skeleton", frame);*/
|
||||
std::cout << "about to call points receiving method" << std::endl;
|
||||
f(points);
|
||||
}
|
||||
}
|
||||
20
src/computervision/OpenPoseVideo.h
Normal file
20
src/computervision/OpenPoseVideo.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <opencv2/dnn.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
class OpenPoseVideo{
|
||||
private:
|
||||
|
||||
public:
|
||||
cv::Mat getBlobFromImage(cv::Mat inputImage);
|
||||
void movementSkeleton(Mat inputImage, Mat inpBlob, std::function<void(std::vector<Point>)> f);
|
||||
void setup();
|
||||
};
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace computervision
|
||||
void SkinDetector::drawSkinColorSampler(Mat input) {
|
||||
int frameWidth = input.size().width, frameHeight = input.size().height;
|
||||
|
||||
int rectangleSize = 20;
|
||||
int rectangleSize = 25;
|
||||
Scalar rectangleColor = Scalar(255, 0, 255);
|
||||
|
||||
skinColorSamplerRectangle1 = Rect(frameWidth / 5, frameHeight / 2, rectangleSize, rectangleSize);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<opencv2\core.hpp>
|
||||
#include <opencv2\core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/imgproc/types_c.h>
|
||||
@@ -17,11 +17,31 @@ namespace computervision
|
||||
public:
|
||||
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);
|
||||
|
||||
/*
|
||||
* @brief calibrates the skin color detector with the given input frame
|
||||
*
|
||||
* @param input the input frame to calibrate from
|
||||
*/
|
||||
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);
|
||||
|
||||
private:
|
||||
|
||||
// thresholds for hsv calculation
|
||||
int hLowThreshold = 0;
|
||||
int hHighThreshold = 0;
|
||||
int sLowThreshold = 0;
|
||||
@@ -29,11 +49,28 @@ namespace computervision
|
||||
int vLowThreshold = 0;
|
||||
int vHighThreshold = 0;
|
||||
|
||||
// wether or not the skindetector has calibrated yet.
|
||||
bool calibrated = false;
|
||||
|
||||
// rectangles that get drawn to show where the skin color will be sampled
|
||||
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 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);
|
||||
};
|
||||
}
|
||||
33
src/computervision/VideoCapture.cpp
Normal file
33
src/computervision/VideoCapture.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "VideoCapture.h"
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
|
||||
namespace videocapture{
|
||||
static cv::VideoCapture cap(0);
|
||||
static std::mutex mtx;
|
||||
|
||||
cv::VideoCapture getCap() {
|
||||
cap.release();
|
||||
|
||||
return cap;
|
||||
}
|
||||
|
||||
cv::Mat readFrame()
|
||||
{
|
||||
std::cout << "reading frame" << std::endl;
|
||||
cv::Mat camFrame, videoFrame;
|
||||
|
||||
mtx.lock();
|
||||
bool res = cap.read(camFrame);
|
||||
std::cout << (res ? "reading worked" : "reading failed") << std::endl;
|
||||
videoFrame = camFrame.clone();
|
||||
mtx.unlock();
|
||||
|
||||
return videoFrame;
|
||||
}
|
||||
|
||||
std::mutex* getMutex()
|
||||
{
|
||||
return &mtx;
|
||||
}
|
||||
}
|
||||
12
src/computervision/VideoCapture.h
Normal file
12
src/computervision/VideoCapture.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/video.hpp>
|
||||
#include <mutex>
|
||||
|
||||
namespace videocapture {
|
||||
cv::VideoCapture getCap();
|
||||
std::mutex* getMutex();
|
||||
cv::Mat readFrame();
|
||||
|
||||
}
|
||||
41
src/computervision/async/async_arm_detection.cpp
Normal file
41
src/computervision/async/async_arm_detection.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
#include "async_arm_detection.h"
|
||||
#include "../OpenPoseVideo.h"
|
||||
#include <thread>
|
||||
#include "../VideoCapture.h"
|
||||
#include <opencv2/dnn.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
AsyncArmDetection::AsyncArmDetection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AsyncArmDetection::run_arm_detection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AsyncArmDetection::start(std::function<void(std::vector<Point>)> points_ready_func, OpenPoseVideo op)
|
||||
{
|
||||
|
||||
auto lambda = [](cv::Mat img, std::function<void(std::vector<Point>)> f, OpenPoseVideo op, cv::Mat inpBlob) {
|
||||
std::cout << "STARTING THREAD LAMBDA" << std::endl;
|
||||
|
||||
//imshow("image", img); 255, Size(368, 368), Scalar(0, 0, 0), false, false);
|
||||
op.movementSkeleton(img, inpBlob, f);
|
||||
//}
|
||||
};
|
||||
|
||||
cv::Mat img = videocapture::readFrame();
|
||||
std::cout << "starting function" << std::endl;
|
||||
cv::Mat inpBlob = op.getBlobFromImage(videocapture::readFrame());
|
||||
|
||||
|
||||
std::thread async_arm_detect_thread(lambda, img, points_ready_func, op, inpBlob);
|
||||
}
|
||||
}
|
||||
22
src/computervision/async/async_arm_detection.h
Normal file
22
src/computervision/async/async_arm_detection.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <opencv2/core/types.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <functional>
|
||||
#include "../OpenPoseVideo.h"
|
||||
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
class AsyncArmDetection
|
||||
{
|
||||
public:
|
||||
AsyncArmDetection(void);
|
||||
|
||||
|
||||
void start(std::function<void(std::vector<cv::Point>)>, computervision::OpenPoseVideo op);
|
||||
private:
|
||||
void run_arm_detection();
|
||||
};
|
||||
|
||||
}
|
||||
127
src/main.cpp
127
src/main.cpp
@@ -1,9 +1,16 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#include <ostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/video.hpp>
|
||||
|
||||
#include "models/model.h"
|
||||
#include "renderEngine/loader.h"
|
||||
@@ -13,6 +20,10 @@
|
||||
#include "toolbox/toolbox.h"
|
||||
|
||||
#include "computervision/ObjectDetection.h"
|
||||
//#include "computervision/OpenPoseImage.h"
|
||||
#include "computervision/OpenPoseVideo.h"
|
||||
|
||||
#include "computervision/async/async_arm_detection.h"
|
||||
|
||||
#pragma comment(lib, "glfw3.lib")
|
||||
#pragma comment(lib, "glew32s.lib")
|
||||
@@ -21,83 +32,105 @@
|
||||
static double UpdateDelta();
|
||||
|
||||
static GLFWwindow* window;
|
||||
computervision::AsyncArmDetection as;
|
||||
computervision::OpenPoseVideo openPoseVideo;
|
||||
|
||||
void retrieve_points(std::vector<Point> arm_points)
|
||||
{
|
||||
std::cout << "got points!!" << std::endl;
|
||||
std::cout << "points: " << arm_points << std::endl;
|
||||
as.start(retrieve_points, openPoseVideo);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#pragma region OPENGL_SETTINGS
|
||||
if (!glfwInit())
|
||||
throw "Could not inditialize glwf";
|
||||
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGT, "SDBA", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
throw "Could not initialize glwf";
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
glewInit();
|
||||
glGetError();
|
||||
#pragma endregion
|
||||
#pragma region OPENGL_SETTINGS
|
||||
if (!glfwInit())
|
||||
throw "Could not inditialize glwf";
|
||||
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGT, "SDBA", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
throw "Could not initialize glwf";
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
glewInit();
|
||||
glGetError();
|
||||
#pragma endregion
|
||||
|
||||
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
});
|
||||
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
});
|
||||
|
||||
|
||||
models::RawModel raw_model = LoadObjModel("res/Tree.obj");
|
||||
models::ModelTexture texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") };
|
||||
models::TexturedModel model = { raw_model, texture };
|
||||
entities::Entity entity(model, glm::vec3(0, -5, -20), glm::vec3(0, 0, 0), 1);
|
||||
models::RawModel raw_model = LoadObjModel("res/Tree.obj");
|
||||
models::ModelTexture texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") };
|
||||
models::TexturedModel model = { raw_model, texture };
|
||||
entities::Entity entity(model, glm::vec3(0, -5, -20), glm::vec3(0, 0, 0), 1);
|
||||
|
||||
shaders::StaticShader shader;
|
||||
shader.Init();
|
||||
render_engine::renderer::Init(shader);
|
||||
shaders::StaticShader shader;
|
||||
shader.Init();
|
||||
render_engine::renderer::Init(shader);
|
||||
|
||||
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));
|
||||
|
||||
computervision::ObjectDetection objDetect;
|
||||
// create object detection object instance
|
||||
computervision::ObjectDetection objDetect;
|
||||
//computervision::OpenPoseImage openPoseImage;
|
||||
|
||||
openPoseVideo.setup();
|
||||
|
||||
|
||||
// set up object detection
|
||||
//objDetect.setup();
|
||||
// set up object detection
|
||||
//objDetect.setup();
|
||||
cv::Mat cameraFrame;
|
||||
|
||||
|
||||
//openPoseVideo.setup();
|
||||
|
||||
|
||||
as.start(retrieve_points, openPoseVideo);
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Update
|
||||
const double delta = UpdateDelta();
|
||||
entity.IncreaseRotation(glm::vec3(0, 1, 0));
|
||||
camera.Move(window);
|
||||
// Update
|
||||
const double delta = UpdateDelta();
|
||||
entity.IncreaseRotation(glm::vec3(0, 1, 0));
|
||||
camera.Move(window);
|
||||
|
||||
// Render
|
||||
render_engine::renderer::Prepare();
|
||||
shader.Start();
|
||||
shader.LoadViewMatrix(camera);
|
||||
render_engine::renderer::Prepare();
|
||||
shader.Start();
|
||||
shader.LoadViewMatrix(camera);
|
||||
|
||||
render_engine::renderer::Render(entity, shader);
|
||||
|
||||
objDetect.setup();
|
||||
render_engine::renderer::Render(entity, shader);
|
||||
|
||||
cameraFrame = objDetect.readCamera();
|
||||
//objDetect.detectHand(cameraFrame);
|
||||
|
||||
// Finish up
|
||||
shader.Stop();
|
||||
shader.Stop();
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// Clean up
|
||||
shader.CleanUp();
|
||||
render_engine::loader::CleanUp();
|
||||
shader.CleanUp();
|
||||
render_engine::loader::CleanUp();
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double UpdateDelta()
|
||||
{
|
||||
double current_time = glfwGetTime();
|
||||
static double last_frame_time = current_time;
|
||||
double delt_time = current_time - last_frame_time;
|
||||
last_frame_time = current_time;
|
||||
return delt_time;
|
||||
double current_time = glfwGetTime();
|
||||
static double last_frame_time = current_time;
|
||||
double delt_time = current_time - last_frame_time;
|
||||
last_frame_time = current_time;
|
||||
return delt_time;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace render_engine
|
||||
void Init(shaders::StaticShader& shader)
|
||||
{
|
||||
const glm::mat4 projectionMatrix =
|
||||
glm::perspective(glm::radians(FOV), (WINDOW_WIDTH / WINDOW_HEIGT), NEAR_PLANE, FAR_PLANE);
|
||||
glm::perspective(glm::radians(FOV), (float)(WINDOW_WIDTH / WINDOW_HEIGT), NEAR_PLANE, FAR_PLANE);
|
||||
|
||||
shader.Start();
|
||||
shader.LoadProjectionMatrix(projectionMatrix);
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
namespace toolbox
|
||||
{
|
||||
#define WINDOW_WIDTH 1400.0f
|
||||
#define WINDOW_HEIGT 800.0f
|
||||
#define WINDOW_WIDTH 1400
|
||||
#define WINDOW_HEIGT 800
|
||||
|
||||
glm::mat4 CreateModelMatrix(glm::vec3 translation, glm::vec3 rotation, float scale);
|
||||
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\computervision\async\async_arm_detection.cpp" />
|
||||
<ClCompile Include="src\computervision\FaceDetector.cpp" />
|
||||
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
|
||||
<ClCompile Include="src\computervision\OpenPoseVideo.cpp" />
|
||||
<ClCompile Include="src\computervision\SkinDetector.cpp" />
|
||||
<ClCompile Include="src\computervision\FingerCount.cpp" />
|
||||
<ClCompile Include="src\computervision\BackgroundRemover.cpp" />
|
||||
<ClCompile Include="src\computervision\VideoCapture.cpp" />
|
||||
<ClCompile Include="src\entities\camera.cpp" />
|
||||
<ClCompile Include="src\entities\entity.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
@@ -35,11 +38,14 @@
|
||||
<ClCompile Include="src\toolbox\toolbox.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h" />
|
||||
<ClInclude Include="src\computervision\FaceDetector.h" />
|
||||
<ClInclude Include="src\computervision\FingerCount.h" />
|
||||
<ClInclude Include="src\computervision\BackgroundRemover.h" />
|
||||
<ClInclude Include="src\computervision\OpenPoseVideo.h" />
|
||||
<ClInclude Include="src\computervision\SkinDetector.h" />
|
||||
<ClInclude Include="src\computervision\ObjectDetection.h" />
|
||||
<ClInclude Include="src\computervision\VideoCapture.h" />
|
||||
<ClInclude Include="src\entities\camera.h" />
|
||||
<ClInclude Include="src\entities\entity.h" />
|
||||
<ClInclude Include="src\models\model.h" />
|
||||
@@ -54,6 +60,11 @@
|
||||
<ItemGroup>
|
||||
<Xml Include="res\haarcascade_frontalface_alt.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\pose\coco\pose_deploy_linevec.prototxt" />
|
||||
<None Include="res\pose\mpi\pose_deploy_linevec_faster_4_stages.prototxt" />
|
||||
<None Include="res\pose\mpi\pose_iter_160000.caffemodel" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{A7ECF1BE-DB22-4BF7-BFF6-E3BF72691EE6}</ProjectGuid>
|
||||
@@ -112,14 +123,16 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\opencv\build\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\opencv\build\x64\vc15\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>C:\opencv\build\include;$(IncludePath);C:\opencv\opencv\build\include</IncludePath>
|
||||
<LibraryPath>C:\opencv\build\x64\vc15\lib;$(LibraryPath);C:\opencv\opencv\build\x64\vc15\lib</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);;C:\opencv\opencv\build\include</IncludePath>
|
||||
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\opencv\opencv\build\x64\vc15\lib</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@@ -151,7 +164,7 @@
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.2\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opencv_world452d.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>opencv_world452d.lib;%(AdditionalDependencies); opencv_world452.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@@ -192,6 +205,7 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)lib\glfw-3.3.2\$(Platform);$(SolutionDir)lib\glew-2.1.0\lib\Release\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies); opencv_world452.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -57,6 +57,15 @@
|
||||
<ClCompile Include="src\computervision\BackgroundRemover.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\computervision\OpenPoseVideo.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\computervision\async\async_arm_detection.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\computervision\VideoCapture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\entities\Camera.h">
|
||||
@@ -104,8 +113,22 @@
|
||||
<ClInclude Include="src\computervision\BackgroundRemover.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\computervision\OpenPoseVideo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\computervision\VideoCapture.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="res\haarcascade_frontalface_alt.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\pose\coco\pose_deploy_linevec.prototxt" />
|
||||
<None Include="res\pose\mpi\pose_deploy_linevec_faster_4_stages.prototxt" />
|
||||
<None Include="res\pose\mpi\pose_iter_160000.caffemodel" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user