Compare commits
3 Commits
feature/as
...
BUGGED/pos
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
612adf6e9b | ||
|
|
25c99abb72 | ||
|
|
9d80cddbd1 |
@@ -1,15 +1,13 @@
|
||||
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/video.hpp>
|
||||
|
||||
#include "ObjectDetection.h"
|
||||
#include "BackgroundRemover.h"
|
||||
#include "SkinDetector.h"
|
||||
#include "FaceDetector.h"
|
||||
#include "FingerCount.h"
|
||||
#include "async/StaticCameraInstance.h"
|
||||
#include "VideoCapture.h"
|
||||
|
||||
using namespace videocapture;
|
||||
namespace computervision
|
||||
{
|
||||
|
||||
@@ -24,20 +22,18 @@ namespace computervision
|
||||
FaceDetector faceDetector;
|
||||
FingerCount fingerCount;
|
||||
|
||||
cv::VideoCapture cap = static_camera::getCap();
|
||||
|
||||
ObjectDetection::ObjectDetection()
|
||||
{
|
||||
}
|
||||
|
||||
cv::Mat ObjectDetection::readCamera() {
|
||||
cap.read(img);
|
||||
return img;
|
||||
}
|
||||
/*videocapture::getMutex()->lock();
|
||||
|
||||
cv::VideoCapture ObjectDetection::getCap()
|
||||
{
|
||||
return cap;
|
||||
videocapture::getCap().read(img);
|
||||
|
||||
videocapture::getMutex()->unlock();*/
|
||||
img = videocapture::readFrame();
|
||||
return img;
|
||||
}
|
||||
|
||||
bool ObjectDetection::detectHand(Mat cameraFrame)
|
||||
@@ -83,8 +79,13 @@ namespace computervision
|
||||
|
||||
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);
|
||||
|
||||
@@ -65,7 +65,6 @@ namespace computervision
|
||||
*/
|
||||
bool drawHandMaskRect(cv::Mat *input);
|
||||
|
||||
|
||||
cv::VideoCapture getCap();
|
||||
|
||||
};
|
||||
|
||||
@@ -39,20 +39,16 @@ namespace computervision
|
||||
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;
|
||||
|
||||
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;
|
||||
@@ -60,8 +56,16 @@ namespace computervision
|
||||
double t = (double)cv::getTickCount();
|
||||
std::cout << "reading input image and blob" << std::endl;
|
||||
|
||||
frame = inputImage;
|
||||
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;
|
||||
|
||||
@@ -69,7 +73,7 @@ namespace computervision
|
||||
|
||||
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];
|
||||
@@ -92,17 +96,16 @@ namespace computervision
|
||||
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);
|
||||
/*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);
|
||||
//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,frame);
|
||||
f(points);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ namespace computervision
|
||||
private:
|
||||
|
||||
public:
|
||||
void movementSkeleton(Mat& inputImage, std::function<void(std::vector<Point>&, cv::Mat& poinst_on_image)> f);
|
||||
cv::Mat getBlobFromImage(cv::Mat inputImage);
|
||||
void movementSkeleton(Mat inputImage, Mat inpBlob, std::function<void(std::vector<Point>)> f);
|
||||
void setup();
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include <opencv2/videoio.hpp>
|
||||
|
||||
namespace static_camera
|
||||
{
|
||||
|
||||
static cv::VideoCapture getCap()
|
||||
{
|
||||
static cv::VideoCapture cap(0);
|
||||
return cap;
|
||||
}
|
||||
};
|
||||
@@ -2,7 +2,10 @@
|
||||
#include "async_arm_detection.h"
|
||||
#include "../OpenPoseVideo.h"
|
||||
#include <thread>
|
||||
#include "StaticCameraInstance.h"
|
||||
#include "../VideoCapture.h"
|
||||
#include <opencv2/dnn.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
|
||||
namespace computervision
|
||||
@@ -12,35 +15,27 @@ namespace computervision
|
||||
|
||||
}
|
||||
|
||||
void AsyncArmDetection::run_arm_detection(std::function<void(std::vector<Point>, cv::Mat poinst_on_image)> points_ready_func, OpenPoseVideo op)
|
||||
void AsyncArmDetection::run_arm_detection()
|
||||
{
|
||||
VideoCapture cap = static_camera::getCap();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
/*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)
|
||||
{
|
||||
//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(&AsyncArmDetection::run_arm_detection,this, points_ready_func, op);
|
||||
|
||||
async_arm_detect_thread.detach(); // makes sure the thread is detached from the variable.
|
||||
std::thread async_arm_detect_thread(lambda, img, points_ready_func, op, inpBlob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <functional>
|
||||
#include "../OpenPoseVideo.h"
|
||||
#include "StaticCameraInstance.h"
|
||||
|
||||
|
||||
namespace computervision
|
||||
@@ -15,9 +14,9 @@ namespace computervision
|
||||
AsyncArmDetection(void);
|
||||
|
||||
|
||||
void start(std::function<void(std::vector<cv::Point>, cv::Mat poinst_on_image)>, computervision::OpenPoseVideo op);
|
||||
void start(std::function<void(std::vector<cv::Point>)>, computervision::OpenPoseVideo op);
|
||||
private:
|
||||
void run_arm_detection(std::function<void(std::vector<Point>, cv::Mat poinst_on_image)> points_ready_func, OpenPoseVideo op);
|
||||
void run_arm_detection();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
29
src/main.cpp
29
src/main.cpp
@@ -32,16 +32,14 @@
|
||||
static double UpdateDelta();
|
||||
|
||||
static GLFWwindow* window;
|
||||
bool points_img_available = false;
|
||||
cv::Mat points_img;
|
||||
computervision::AsyncArmDetection as;
|
||||
computervision::OpenPoseVideo openPoseVideo;
|
||||
|
||||
void retrieve_points(std::vector<Point> arm_points, cv::Mat points_on_image)
|
||||
void retrieve_points(std::vector<Point> arm_points)
|
||||
{
|
||||
|
||||
std::cout << "got points!!" << std::endl;
|
||||
std::cout << "points: " << arm_points << std::endl;
|
||||
points_img = points_on_image;
|
||||
points_img_available = true;
|
||||
as.start(retrieve_points, openPoseVideo);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@@ -81,22 +79,19 @@ int main(void)
|
||||
// create object detection object instance
|
||||
computervision::ObjectDetection objDetect;
|
||||
//computervision::OpenPoseImage openPoseImage;
|
||||
computervision::OpenPoseVideo openPoseVideo;
|
||||
|
||||
openPoseVideo.setup();
|
||||
|
||||
|
||||
// set up object detection
|
||||
//objDetect.setup();
|
||||
//cv::VideoCapture cam = objDetect.getCap();
|
||||
cv::Mat img;
|
||||
cv::VideoCapture cap = objDetect.getCap();
|
||||
//cam.read(img);
|
||||
//imshow("camera in main loop", img);
|
||||
cv::Mat cameraFrame;
|
||||
|
||||
|
||||
computervision::AsyncArmDetection as;
|
||||
//openPoseVideo.setup();
|
||||
|
||||
as.start(retrieve_points,openPoseVideo);
|
||||
|
||||
as.start(retrieve_points, openPoseVideo);
|
||||
|
||||
|
||||
// Main game loop
|
||||
@@ -115,12 +110,8 @@ int main(void)
|
||||
|
||||
render_engine::renderer::Render(entity, shader);
|
||||
|
||||
cameraFrame = objDetect.readCamera();
|
||||
//objDetect.detectHand(cameraFrame);
|
||||
if (points_img_available)
|
||||
{
|
||||
imshow("points", points_img);
|
||||
points_img_available = false;
|
||||
}
|
||||
|
||||
// Finish up
|
||||
shader.Stop();
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<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" />
|
||||
@@ -38,13 +39,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h" />
|
||||
<ClInclude Include="src\computervision\async\StaticCameraInstance.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" />
|
||||
@@ -60,7 +61,6 @@
|
||||
<Xml Include="res\haarcascade_frontalface_alt.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\Avans Hogeschool\Kim Veldhoen - Proftaak 2.4\pose_iter_160000.caffemodel" />
|
||||
<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" />
|
||||
@@ -131,8 +131,8 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>C:\opencv\build\include\;$(VC_IncludePath);$(WindowsSDK_IncludePath);C:\opencv\opencv\build\include</IncludePath>
|
||||
<LibraryPath>C:\opencv\build\x64\vc15\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\opencv\opencv\build\x64\vc15\lib</LibraryPath>
|
||||
<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>
|
||||
@@ -205,7 +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>opencv_world452.lib;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)</AdditionalDependencies>
|
||||
<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" />
|
||||
|
||||
@@ -63,6 +63,9 @@
|
||||
<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">
|
||||
@@ -116,7 +119,7 @@
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\computervision\async\StaticCameraInstance.h">
|
||||
<ClInclude Include="src\computervision\VideoCapture.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
@@ -127,6 +130,5 @@
|
||||
<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" />
|
||||
<None Include="..\..\Avans Hogeschool\Kim Veldhoen - Proftaak 2.4\pose_iter_160000.caffemodel" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user