merge Feature/hand control int develop #7
@@ -1,108 +0,0 @@
|
||||
#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);
|
||||
|
||||
net.setPreferableBackend(DNN_TARGET_CPU);
|
||||
}
|
||||
|
||||
void OpenPoseVideo::movementSkeleton(Mat& inputImage, std::function<void(std::vector<Point>&, cv::Mat& poinst_on_image)> f) {
|
||||
std::cout << "movement skeleton start" << std::endl;
|
||||
|
||||
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();
|
||||
std::cout << "reading input image and blob" << std::endl;
|
||||
|
||||
frame = inputImage;
|
||||
Mat inpBlob = blobFromImage(frame, 1.0 / 255, Size(inWidth, inHeight), Scalar(0, 0, 0), false, false);
|
||||
|
||||
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();
|
||||
std::cout << "time took to set input and forward: " << t << std::endl;
|
||||
|
||||
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);
|
||||
std::cout << "time taken: " << t << std::endl;
|
||||
//imshow("Output-Keypoints", frame);
|
||||
//imshow("Output-Skeleton", frame);
|
||||
std::cout << "about to call points receiving method" << std::endl;
|
||||
f(points,frame);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#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, std::function<void(std::vector<Point>&, cv::Mat& poinst_on_image)> f);
|
||||
void setup();
|
||||
};
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#include <iostream>
|
||||
#include "async_arm_detection.h"
|
||||
#include "../OpenPoseVideo.h"
|
||||
#include <thread>
|
||||
#include "StaticCameraInstance.h"
|
||||
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
AsyncArmDetection::AsyncArmDetection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AsyncArmDetection::run_arm_detection(std::function<void(std::vector<Point>, cv::Mat poinst_on_image)> points_ready_func, OpenPoseVideo op)
|
||||
{
|
||||
VideoCapture cap = static_camera::getCap();
|
||||
|
||||
std::cout << "STARTING THREAD LAMBDA" << std::endl;
|
||||
/*cv::VideoCapture cap = static_camera::GetCap();*/
|
||||
|
||||
if (!cap.isOpened())
|
||||
{
|
||||
std::cout << "capture was closed, opening..." << std::endl;
|
||||
cap.open(0);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
Mat img;
|
||||
cap.read(img);
|
||||
op.movementSkeleton(img, points_ready_func);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncArmDetection::start(std::function<void(std::vector<Point>, cv::Mat poinst_on_image)> points_ready_func, OpenPoseVideo op)
|
||||
{
|
||||
|
||||
std::cout << "starting function" << std::endl;
|
||||
|
||||
|
||||
std::thread async_arm_detect_thread(&AsyncArmDetection::run_arm_detection,this, points_ready_func, op);
|
||||
|
||||
async_arm_detect_thread.detach(); // makes sure the thread is detached from the variable.
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <opencv2/core/types.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <functional>
|
||||
#include "../OpenPoseVideo.h"
|
||||
#include "StaticCameraInstance.h"
|
||||
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
class AsyncArmDetection
|
||||
{
|
||||
public:
|
||||
AsyncArmDetection(void);
|
||||
|
||||
|
||||
void start(std::function<void(std::vector<cv::Point>, cv::Mat poinst_on_image)>, computervision::OpenPoseVideo op);
|
||||
private:
|
||||
void run_arm_detection(std::function<void(std::vector<Point>, cv::Mat poinst_on_image)> points_ready_func, OpenPoseVideo op);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ namespace computervision
|
||||
skin_detector.drawSkinColorSampler(camera_frame,start_x_pos,start_y_pos,region_width,region_height);
|
||||
|
||||
// remove background from image
|
||||
|
||||
foreground = background_remover.getForeground(input_frame);
|
||||
|
||||
// detect the hand contours
|
||||
@@ -67,7 +68,7 @@ namespace computervision
|
||||
//imshow("output" + region_id, frame_out);
|
||||
//imshow("foreground" + region_id, foreground);
|
||||
//imshow("handMask" + region_id, handMask);
|
||||
/*imshow("handDetection", fingerCountDebug);*/
|
||||
//imshow("handDetection", fingerCountDebug);
|
||||
|
||||
hand_present = hand_calibrator.CheckIfHandPresent(handMask,handcalibration::HandDetectionType::GAME);
|
||||
//std::string text = (hand_present ? "hand" : "no");
|
||||
|
||||
@@ -23,5 +23,7 @@ namespace entities
|
||||
this->rotation.y += rotation.y;
|
||||
this->rotation.z += rotation.z;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace entities
|
||||
inline glm::vec3 GetPosition() const { return position; }
|
||||
inline void SetPosition(const ::glm::vec3& position) { this->position = position; }
|
||||
inline glm::vec3 GetRotation() const { return rotation; }
|
||||
inline void SetRotation(const ::glm::vec3& rotation) { this->rotation = rotation; }
|
||||
void SetRotation(const ::glm::vec3& rotation) { this->rotation = rotation; }
|
||||
inline float GetScale() const { return scale; }
|
||||
inline void SetScale(const float scale) { this->scale = scale; }
|
||||
};
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
#include"../renderEngine/loader.h"
|
||||
namespace entities
|
||||
{
|
||||
float movement_speed;
|
||||
float down_speed;
|
||||
float side_speed;
|
||||
int movement_speed, down_speed, side_speed;
|
||||
bool is_playing;
|
||||
|
||||
|
||||
MainCharacter::MainCharacter(const models::TexturedModel& model, const glm::vec3& position,
|
||||
const glm::vec3& rotation, float scale, const collision::Box& bounding_box)
|
||||
: CollisionEntity(model, position, rotation, scale, bounding_box)
|
||||
@@ -19,63 +18,58 @@ namespace entities
|
||||
is_playing = true;
|
||||
}
|
||||
|
||||
void MainCharacter::Move(GLFWwindow* window)
|
||||
void MainCharacter::Move(std::vector<computervision::HandDetectRegion*> regions)
|
||||
{
|
||||
if (is_playing) {
|
||||
movement_speed = -2.0f; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||
down_speed = -1.0f; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED
|
||||
side_speed = 0; //Side speed adjustment
|
||||
computervision::HandDetectRegion* reg_left = regions.at(0);
|
||||
computervision::HandDetectRegion* reg_up = regions.at(1);
|
||||
computervision::HandDetectRegion* reg_right = regions.at(2);
|
||||
|
||||
double delta_time = UpdateDelta();
|
||||
|
||||
if (is_playing) {
|
||||
movement_speed = -15; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||
down_speed = -50; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED
|
||||
side_speed = 0; //Side speed adjustment
|
||||
//For gameplay with use of keyboard keys: W, A, S, D
|
||||
//W: Go forward
|
||||
//A: Go left
|
||||
//S: Go backwards
|
||||
//D: Go right
|
||||
//TODO Implement CV actions
|
||||
SetRotation(glm::vec3(0, 90, 0));
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
{
|
||||
movement_speed -= SIDE_SPEED;
|
||||
}
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
{
|
||||
movement_speed += SIDE_SPEED;
|
||||
}
|
||||
//top right
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
SetRotation(glm::vec3(0, 90, 0));
|
||||
if (reg_up->IsHandPresent() && reg_left->IsHandPresent())
|
||||
{
|
||||
side_speed += SIDE_SPEED;
|
||||
down_speed += UP_SPEED;
|
||||
down_speed += UP_SPEED/2;
|
||||
SetRotation(glm::vec3(10, 90, 0));
|
||||
}
|
||||
//right
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
if (reg_left->IsHandPresent())
|
||||
{
|
||||
side_speed += SIDE_SPEED;
|
||||
}
|
||||
//top left
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
if (reg_up->IsHandPresent() && reg_right->IsHandPresent())
|
||||
{
|
||||
down_speed += UP_SPEED;
|
||||
down_speed += UP_SPEED/2;
|
||||
side_speed -= SIDE_SPEED;
|
||||
SetRotation(glm::vec3(10, 90, 0));
|
||||
}
|
||||
//left
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
if (reg_right->IsHandPresent())
|
||||
{
|
||||
side_speed -= SIDE_SPEED;
|
||||
}
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
if (reg_up->IsHandPresent())
|
||||
{
|
||||
down_speed += UP_SPEED;
|
||||
SetRotation(glm::vec3(10, 90, 0));
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||
{
|
||||
down_speed -= UP_SPEED;
|
||||
}
|
||||
}
|
||||
IncreasePosition(glm::vec3(side_speed, down_speed, movement_speed));
|
||||
IncreasePosition(glm::vec3(side_speed*delta_time, down_speed*delta_time, movement_speed*delta_time));
|
||||
std::cout << "delta time char: "<< delta_time << std::endl;
|
||||
|
||||
//Use only for binding bee to house, such that it doesn't go outside of the room.
|
||||
//TODO delete when boundingbox is implemented!
|
||||
@@ -85,7 +79,7 @@ namespace entities
|
||||
else if (position.y < -40) position.y = -40;
|
||||
//Move player bounding box according to the position on screen
|
||||
MoveCollisionBox();
|
||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
||||
if (reg_right->IsHandPresent() && reg_left->IsHandPresent())
|
||||
{
|
||||
is_playing = true;
|
||||
}
|
||||
@@ -98,7 +92,12 @@ namespace entities
|
||||
std::cout << "collision" << std::endl;
|
||||
}
|
||||
|
||||
bool MainCharacter::GetOnCollide() {
|
||||
return is_playing;
|
||||
double MainCharacter::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;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "collision_entity.h"
|
||||
#include "../shaders/entity_shader.h"
|
||||
#include "../computervision/HandDetectRegion.h"
|
||||
|
||||
namespace entities
|
||||
{
|
||||
@@ -9,8 +10,8 @@ namespace entities
|
||||
* This class contains the information about the player model
|
||||
*/
|
||||
class MainCharacter : public CollisionEntity {
|
||||
const float SIDE_SPEED = 0.8f; //Standard movement speed for left/right movement
|
||||
const float UP_SPEED = 2.0f; //Standard movement speed for up movement
|
||||
const int SIDE_SPEED = 40; //Standard movement speed for left/right movement
|
||||
const int UP_SPEED = 100; //Standard movement speed for up movement
|
||||
public:
|
||||
/*
|
||||
* @brief: Constructor for the main character model
|
||||
@@ -31,10 +32,10 @@ namespace entities
|
||||
*
|
||||
* @return: Vector with the adjusted side_speed, down_speed, and movement_speed
|
||||
*/
|
||||
void Move(GLFWwindow* window);
|
||||
void Move(std::vector<computervision::HandDetectRegion*> regions);
|
||||
|
||||
void OnCollide(const collision::Collision& collision) override;
|
||||
|
||||
bool GetOnCollide();
|
||||
|
||||
double UpdateDelta();
|
||||
};
|
||||
}
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -29,12 +29,7 @@
|
||||
#include "scenes/startup_Scene.h"
|
||||
#include "scenes/game_Over_Scene.h"
|
||||
#include "entities/collision_entity.h"
|
||||
|
||||
#include "computervision/object_detection.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")
|
||||
@@ -50,15 +45,6 @@ scene::Scene* current_scene;
|
||||
bool points_img_available = false;
|
||||
cv::Mat points_img;
|
||||
|
||||
void retrieve_points(std::vector<Point> arm_points, cv::Mat points_on_image)
|
||||
{
|
||||
|
||||
std::cout << "got points!!" << std::endl;
|
||||
std::cout << "points: " << arm_points << std::endl;
|
||||
points_img = points_on_image;
|
||||
points_img_available = true;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#pragma region OPENGL_SETTINGS
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace scene
|
||||
}
|
||||
|
||||
/**
|
||||
* temporary!!!!
|
||||
* temporary?
|
||||
* just to make some bounding boxes
|
||||
*/
|
||||
collision::Box create_bounding_box(glm::vec3 size, glm::vec3 pos, int scale) {
|
||||
@@ -190,6 +190,9 @@ namespace scene
|
||||
});
|
||||
pause_guis.push_back(&pause_button_quit);
|
||||
|
||||
regions.push_back(®_left);
|
||||
regions.push_back(®_up);
|
||||
regions.push_back(®_right);
|
||||
|
||||
//the scene loop, this while loop represent the scene
|
||||
while (return_value == scene::Scenes::INGAME)
|
||||
@@ -260,7 +263,8 @@ namespace scene
|
||||
{
|
||||
UpdateDeltaTime();
|
||||
//camera.Move(window);
|
||||
main_character->Move(window);
|
||||
update_hand_detection();
|
||||
main_character->Move(regions);
|
||||
if (!main_character.get()->GetOnCollide())
|
||||
{
|
||||
*ptr = score;
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
<ClInclude Include="src\computervision\hand_detect_region.h" />
|
||||
<ClInclude Include="src\scenes\in_Game_Scene.h" />
|
||||
<ClInclude Include="src\scenes\scene.h" />
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h" />
|
||||
<ClInclude Include="src\computervision\async\StaticCameraInstance.h" />
|
||||
<ClInclude Include="src\computervision\finger_count.h" />
|
||||
<ClInclude Include="src\computervision\background_remover.h" />
|
||||
|
||||
@@ -3,12 +3,19 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\collision\collision_handler.cpp" />
|
||||
<ClCompile Include="src\scenes\in_Game_Scene.cpp" />
|
||||
<<<<<<< HEAD
|
||||
<ClCompile Include="src\computervision\ObjectDetection.cpp" />
|
||||
<ClCompile Include="src\computervision\SkinDetector.cpp" />
|
||||
<ClCompile Include="src\computervision\FingerCount.cpp" />
|
||||
<ClCompile Include="src\computervision\BackgroundRemover.cpp" />
|
||||
=======
|
||||
<ClCompile Include="src\computervision\async\async_arm_detection.cpp" />
|
||||
<ClCompile Include="src\computervision\object_detection.cpp" />
|
||||
<ClCompile Include="src\computervision\OpenPoseVideo.cpp" />
|
||||
<ClCompile Include="src\computervision\skin_detector.cpp" />
|
||||
<ClCompile Include="src\computervision\finger_count.cpp" />
|
||||
<ClCompile Include="src\computervision\background_remover.cpp" />
|
||||
>>>>>>> develop
|
||||
<ClCompile Include="src\entities\camera.cpp" />
|
||||
<ClCompile Include="src\entities\collision_entity.cpp" />
|
||||
<ClCompile Include="src\entities\entity.cpp" />
|
||||
@@ -23,7 +30,11 @@
|
||||
<ClCompile Include="src\toolbox\toolbox.cpp" />
|
||||
<ClCompile Include="src\scenes\startup_Scene.cpp" />
|
||||
<ClCompile Include="src\computervision\calibration\HandCalibrator.cpp" />
|
||||
<<<<<<< HEAD
|
||||
<ClCompile Include="src\computervision\HandDetectRegion.cpp" />
|
||||
=======
|
||||
<ClCompile Include="src\computervision\hand_detect_region.cpp" />
|
||||
>>>>>>> develop
|
||||
<ClCompile Include="src\entities\main_character.cpp" />
|
||||
<ClCompile Include="src\entities\house_generator.cpp" />
|
||||
<ClCompile Include="src\computervision\MenuTest.cpp" />
|
||||
@@ -94,11 +105,9 @@
|
||||
<ClInclude Include="src\collision\collision_handler.h" />
|
||||
<ClInclude Include="src\scenes\in_Game_Scene.h" />
|
||||
<ClInclude Include="src\scenes\scene.h" />
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h" />
|
||||
<ClInclude Include="src\computervision\async\StaticCameraInstance.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\entities\camera.h" />
|
||||
|
||||
Reference in New Issue
Block a user