Compare commits
3 Commits
feature/im
...
feature/po
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23624aea3f | ||
|
|
a68c6a57bf | ||
|
|
078a6ce66d |
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
@@ -1,25 +0,0 @@
|
|||||||
#include "MenuTest.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace computervision
|
|
||||||
{
|
|
||||||
int menu_item_array[4] = { 1, 2, 3, 4 };
|
|
||||||
float item_number = 0;
|
|
||||||
|
|
||||||
MenuTest::MenuTest(void) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int MenuTest::GetMenuItem(bool hand_state) {
|
|
||||||
item_number += 0.20f;
|
|
||||||
|
|
||||||
|
|
||||||
int temp_item_number = item_number;
|
|
||||||
//If temp_item_number is equal to the size of the array, set item_number bac to zero to loop through the array again
|
|
||||||
if (temp_item_number == sizeof(menu_item_array) / sizeof(menu_item_array[0])) {
|
|
||||||
item_number = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return menu_item_array[temp_item_number];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
namespace computervision
|
|
||||||
{
|
|
||||||
class MenuTest {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Constructor for the class MenuTest, loads in array with menu items
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
MenuTest(void);
|
|
||||||
/**
|
|
||||||
* @brief Returns the itemnumber in an array
|
|
||||||
*
|
|
||||||
* @param input_bool is either true or false, depending on the recognized hand gesture
|
|
||||||
*/
|
|
||||||
int GetMenuItem(bool input_bool);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace computervision
|
namespace computervision
|
||||||
{
|
{
|
||||||
cv::VideoCapture cap(0);
|
cv::VideoCapture cap(1);
|
||||||
|
|
||||||
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
|
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
|
||||||
|
|
||||||
|
|||||||
95
src/computervision/OpenPoseVideo.cpp
Normal file
95
src/computervision/OpenPoseVideo.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#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;
|
||||||
|
|
||||||
|
void OpenPoseVideo::setup() {
|
||||||
|
net = readNetFromCaffe(protoFile, weightsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenPoseVideo::movementSkeleton(Mat inputImage) {
|
||||||
|
|
||||||
|
int inWidth = 368;
|
||||||
|
int inHeight = 368;
|
||||||
|
float thresh = 0.01;
|
||||||
|
|
||||||
|
Mat frame;
|
||||||
|
int frameWidth = inputImage.size().width;
|
||||||
|
int frameHeight = inputImage.size().height;
|
||||||
|
|
||||||
|
double t = (double)cv::getTickCount();
|
||||||
|
|
||||||
|
frame = inputImage;
|
||||||
|
Mat inpBlob = blobFromImage(frame, 1.0 / 255, Size(inWidth, inHeight), Scalar(0, 0, 0), false, false);
|
||||||
|
|
||||||
|
net.setInput(inpBlob);
|
||||||
|
|
||||||
|
Mat output = net.forward();
|
||||||
|
|
||||||
|
int H = output.size[2];
|
||||||
|
int W = output.size[3];
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
imshow("Output-Keypoints", frame);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/computervision/OpenPoseVideo.h
Normal file
19
src/computervision/OpenPoseVideo.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#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:
|
||||||
|
void movementSkeleton(Mat inputImage);
|
||||||
|
void setup();
|
||||||
|
};
|
||||||
|
}
|
||||||
62
src/main.cpp
62
src/main.cpp
@@ -5,8 +5,6 @@
|
|||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
#include <opencv2/videoio.hpp>
|
#include <opencv2/videoio.hpp>
|
||||||
@@ -19,8 +17,9 @@
|
|||||||
#include "shaders/static_shader.h"
|
#include "shaders/static_shader.h"
|
||||||
#include "toolbox/toolbox.h"
|
#include "toolbox/toolbox.h"
|
||||||
|
|
||||||
#include "computervision/MenuTest.h"
|
|
||||||
#include "computervision/ObjectDetection.h"
|
#include "computervision/ObjectDetection.h"
|
||||||
|
//#include "computervision/OpenPoseImage.h"
|
||||||
|
#include "computervision/OpenPoseVideo.h"
|
||||||
|
|
||||||
#pragma comment(lib, "glfw3.lib")
|
#pragma comment(lib, "glfw3.lib")
|
||||||
#pragma comment(lib, "glew32s.lib")
|
#pragma comment(lib, "glew32s.lib")
|
||||||
@@ -29,7 +28,7 @@
|
|||||||
static double UpdateDelta();
|
static double UpdateDelta();
|
||||||
|
|
||||||
static GLFWwindow* window;
|
static GLFWwindow* window;
|
||||||
int chosen_item = 0;
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -67,12 +66,17 @@ int main(void)
|
|||||||
|
|
||||||
// create object detection object instance
|
// create object detection object instance
|
||||||
computervision::ObjectDetection objDetect;
|
computervision::ObjectDetection objDetect;
|
||||||
|
//computervision::OpenPoseImage openPoseImage;
|
||||||
|
computervision::OpenPoseVideo openPoseVideo;
|
||||||
|
|
||||||
|
|
||||||
// set up object detection
|
// set up object detection
|
||||||
//objDetect.setup();
|
//objDetect.setup();
|
||||||
cv::Mat cameraFrame;
|
cv::Mat cameraFrame;
|
||||||
|
|
||||||
|
|
||||||
|
openPoseVideo.setup();
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
@@ -90,54 +94,8 @@ int main(void)
|
|||||||
render_engine::renderer::Render(entity, shader);
|
render_engine::renderer::Render(entity, shader);
|
||||||
|
|
||||||
cameraFrame = objDetect.readCamera();
|
cameraFrame = objDetect.readCamera();
|
||||||
|
//objDetect.detectHand(cameraFrame);
|
||||||
////////////////////////// KIMS SHIT ////////////////////////////////////
|
openPoseVideo.movementSkeleton(cameraFrame);
|
||||||
computervision::MenuTest menu_test;
|
|
||||||
|
|
||||||
//Get hand state from camera
|
|
||||||
bool hand_detection = objDetect.detectHand(cameraFrame);
|
|
||||||
|
|
||||||
if (hand_detection)
|
|
||||||
{
|
|
||||||
std::cout << "hand is opened" << std::endl;
|
|
||||||
|
|
||||||
//Loop through menu items
|
|
||||||
chosen_item = menu_test.GetMenuItem(true);
|
|
||||||
|
|
||||||
//For debug only, to see if chosen item is selected properly when hand is opened
|
|
||||||
std::cout << "chosen item: " << chosen_item << std::endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (!hand_detection)
|
|
||||||
{
|
|
||||||
//for debug only, to see if the chosen item is selected properly when hand is closed
|
|
||||||
std::cout << "hand is closed" << std::endl;
|
|
||||||
//std::cout << "item to start: " << chosen_item << std::endl;
|
|
||||||
|
|
||||||
//TODO link chosen item to the correct game states
|
|
||||||
switch (chosen_item)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
//Game state 0
|
|
||||||
std::cout << "in case: " << chosen_item << std::endl;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//Game state 1
|
|
||||||
std::cout << "in case: " << chosen_item << std::endl;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
//Game state 2
|
|
||||||
std::cout << "in case: " << chosen_item << std::endl;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
//Game state 3
|
|
||||||
std::cout << "in case: " << chosen_item << std::endl;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////// END OF KIMS SHIT ///////////////////////////////
|
|
||||||
|
|
||||||
// Finish up
|
// Finish up
|
||||||
shader.Stop();
|
shader.Stop();
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\computervision\FaceDetector.cpp" />
|
<ClCompile Include="src\computervision\FaceDetector.cpp" />
|
||||||
<ClCompile Include="src\computervision\MenuTest.cpp" />
|
|
||||||
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
|
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
|
||||||
|
<ClCompile Include="src\computervision\OpenPoseVideo.cpp" />
|
||||||
<ClCompile Include="src\computervision\SkinDetector.cpp" />
|
<ClCompile Include="src\computervision\SkinDetector.cpp" />
|
||||||
<ClCompile Include="src\computervision\FingerCount.cpp" />
|
<ClCompile Include="src\computervision\FingerCount.cpp" />
|
||||||
<ClCompile Include="src\computervision\BackgroundRemover.cpp" />
|
<ClCompile Include="src\computervision\BackgroundRemover.cpp" />
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
<ClInclude Include="src\computervision\FaceDetector.h" />
|
<ClInclude Include="src\computervision\FaceDetector.h" />
|
||||||
<ClInclude Include="src\computervision\FingerCount.h" />
|
<ClInclude Include="src\computervision\FingerCount.h" />
|
||||||
<ClInclude Include="src\computervision\BackgroundRemover.h" />
|
<ClInclude Include="src\computervision\BackgroundRemover.h" />
|
||||||
<ClInclude Include="src\computervision\MenuTest.h" />
|
<ClInclude Include="src\computervision\OpenPoseVideo.h" />
|
||||||
<ClInclude Include="src\computervision\SkinDetector.h" />
|
<ClInclude Include="src\computervision\SkinDetector.h" />
|
||||||
<ClInclude Include="src\computervision\ObjectDetection.h" />
|
<ClInclude Include="src\computervision\ObjectDetection.h" />
|
||||||
<ClInclude Include="src\entities\camera.h" />
|
<ClInclude Include="src\entities\camera.h" />
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
<ClCompile Include="src\computervision\BackgroundRemover.cpp">
|
<ClCompile Include="src\computervision\BackgroundRemover.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\computervision\MenuTest.cpp">
|
<ClCompile Include="src\computervision\OpenPoseVideo.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
<ClInclude Include="src\computervision\BackgroundRemover.h">
|
<ClInclude Include="src\computervision\BackgroundRemover.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\computervision\MenuTest.h">
|
<ClInclude Include="src\computervision\OpenPoseVideo.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user