Compare commits
3 Commits
main
...
BUGGED/pos
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
612adf6e9b | ||
|
|
25c99abb72 | ||
|
|
9d80cddbd1 |
@@ -1,17 +1,15 @@
|
|||||||
|
|
||||||
#include <opencv2/videoio.hpp>
|
|
||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
#include <opencv2/video.hpp>
|
|
||||||
|
|
||||||
#include "ObjectDetection.h"
|
#include "ObjectDetection.h"
|
||||||
#include "BackgroundRemover.h"
|
#include "BackgroundRemover.h"
|
||||||
#include "SkinDetector.h"
|
#include "SkinDetector.h"
|
||||||
#include "FaceDetector.h"
|
#include "FaceDetector.h"
|
||||||
#include "FingerCount.h"
|
#include "FingerCount.h"
|
||||||
|
#include "VideoCapture.h"
|
||||||
|
|
||||||
|
using namespace videocapture;
|
||||||
namespace computervision
|
namespace computervision
|
||||||
{
|
{
|
||||||
cv::VideoCapture cap(0);
|
|
||||||
|
|
||||||
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
|
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
|
||||||
|
|
||||||
@@ -29,13 +27,13 @@ namespace computervision
|
|||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat ObjectDetection::readCamera() {
|
cv::Mat ObjectDetection::readCamera() {
|
||||||
cap.read(img);
|
/*videocapture::getMutex()->lock();
|
||||||
return img;
|
|
||||||
}
|
|
||||||
|
|
||||||
cv::VideoCapture ObjectDetection::getCap()
|
videocapture::getCap().read(img);
|
||||||
{
|
|
||||||
return cap;
|
videocapture::getMutex()->unlock();*/
|
||||||
|
img = videocapture::readFrame();
|
||||||
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectDetection::detectHand(Mat cameraFrame)
|
bool ObjectDetection::detectHand(Mat cameraFrame)
|
||||||
@@ -81,8 +79,13 @@ namespace computervision
|
|||||||
|
|
||||||
void ObjectDetection::calculateDifference()
|
void ObjectDetection::calculateDifference()
|
||||||
{
|
{
|
||||||
cap.read(img);
|
//videocapture::getMutex()->lock();
|
||||||
cap.read(img2);
|
//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(img, imgGray, cv::COLOR_RGBA2GRAY);
|
||||||
cv::cvtColor(img2, img2Gray, cv::COLOR_RGBA2GRAY);
|
cv::cvtColor(img2, img2Gray, cv::COLOR_RGBA2GRAY);
|
||||||
|
|||||||
@@ -39,18 +39,16 @@ namespace computervision
|
|||||||
int nPoints = 18;
|
int nPoints = 18;
|
||||||
#endif
|
#endif
|
||||||
Net net;
|
Net net;
|
||||||
|
int inWidth = 368;
|
||||||
|
int inHeight = 368;
|
||||||
|
float thresh = 0.01;
|
||||||
|
|
||||||
void OpenPoseVideo::setup() {
|
void OpenPoseVideo::setup() {
|
||||||
net = readNetFromCaffe(protoFile, weightsFile);
|
net = readNetFromCaffe(protoFile, weightsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenPoseVideo::movementSkeleton(Mat inputImage, std::function<void(std::vector<Point>)> f) {
|
cv::Mat OpenPoseVideo::getBlobFromImage(cv::Mat inputImage)
|
||||||
std::cout << "movement skeleton start" << std::endl;
|
{
|
||||||
|
|
||||||
int inWidth = 368;
|
|
||||||
int inHeight = 368;
|
|
||||||
float thresh = 0.01;
|
|
||||||
|
|
||||||
Mat frame;
|
Mat frame;
|
||||||
int frameWidth = inputImage.size().width;
|
int frameWidth = inputImage.size().width;
|
||||||
int frameHeight = inputImage.size().height;
|
int frameHeight = inputImage.size().height;
|
||||||
@@ -58,9 +56,17 @@ namespace computervision
|
|||||||
double t = (double)cv::getTickCount();
|
double t = (double)cv::getTickCount();
|
||||||
std::cout << "reading input image and blob" << std::endl;
|
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);
|
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;
|
std::cout << "done reading image and blob" << std::endl;
|
||||||
|
|
||||||
net.setInput(inpBlob);
|
net.setInput(inpBlob);
|
||||||
@@ -68,6 +74,7 @@ namespace computervision
|
|||||||
std::cout << "done setting input to net" << std::endl;
|
std::cout << "done setting input to net" << std::endl;
|
||||||
Mat output = net.forward();
|
Mat output = net.forward();
|
||||||
|
|
||||||
|
|
||||||
int H = output.size[2];
|
int H = output.size[2];
|
||||||
int W = output.size[3];
|
int W = output.size[3];
|
||||||
|
|
||||||
@@ -89,15 +96,15 @@ namespace computervision
|
|||||||
p.x *= (float)frameWidth / W;
|
p.x *= (float)frameWidth / W;
|
||||||
p.y *= (float)frameHeight / H;
|
p.y *= (float)frameHeight / H;
|
||||||
|
|
||||||
circle(frame, cv::Point((int)p.x, (int)p.y), 8, Scalar(0, 255, 255), -1);
|
/*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);
|
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;
|
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);
|
//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-Keypoints", frameCopy);
|
||||||
imshow("Output-Skeleton", frame);
|
/*imshow("Output-Skeleton", frame);*/
|
||||||
std::cout << "about to call points receiving method" << std::endl;
|
std::cout << "about to call points receiving method" << std::endl;
|
||||||
f(points);
|
f(points);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ namespace computervision
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void movementSkeleton(Mat inputImage,std::function<void(std::vector<Point>)> f);
|
cv::Mat getBlobFromImage(cv::Mat inputImage);
|
||||||
|
void movementSkeleton(Mat inputImage, Mat inpBlob, std::function<void(std::vector<Point>)> f);
|
||||||
void setup();
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
#include "async_arm_detection.h"
|
#include "async_arm_detection.h"
|
||||||
#include "../OpenPoseVideo.h"
|
#include "../OpenPoseVideo.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "../VideoCapture.h"
|
||||||
|
#include <opencv2/dnn.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace computervision
|
namespace computervision
|
||||||
@@ -16,28 +20,22 @@ namespace computervision
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncArmDetection::start(std::function<void(std::vector<Point>)> points_ready_func, cv::VideoCapture cap, OpenPoseVideo op)
|
void AsyncArmDetection::start(std::function<void(std::vector<Point>)> points_ready_func, OpenPoseVideo op)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto lambda = [](std::function<void(std::vector<Point>)> f, cv::VideoCapture c, 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;
|
std::cout << "STARTING THREAD LAMBDA" << std::endl;
|
||||||
cv::VideoCapture cap(0);
|
|
||||||
|
|
||||||
if (!cap.isOpened())
|
//imshow("image", img); 255, Size(368, 368), Scalar(0, 0, 0), false, false);
|
||||||
{
|
op.movementSkeleton(img, inpBlob, f);
|
||||||
std::cout << "error opening video" << std::endl;
|
//}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Mat img;
|
|
||||||
cap.read(img);
|
|
||||||
op.movementSkeleton(img, f);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cv::Mat img = videocapture::readFrame();
|
||||||
std::cout << "starting function" << std::endl;
|
std::cout << "starting function" << std::endl;
|
||||||
std::thread async_arm_detect_thread(lambda, points_ready_func, cap, op);
|
cv::Mat inpBlob = op.getBlobFromImage(videocapture::readFrame());
|
||||||
|
|
||||||
|
|
||||||
|
std::thread async_arm_detect_thread(lambda, img, points_ready_func, op, inpBlob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace computervision
|
|||||||
AsyncArmDetection(void);
|
AsyncArmDetection(void);
|
||||||
|
|
||||||
|
|
||||||
void start(std::function<void(std::vector<cv::Point>)>, cv::VideoCapture cap, computervision::OpenPoseVideo op);
|
void start(std::function<void(std::vector<cv::Point>)>, computervision::OpenPoseVideo op);
|
||||||
private:
|
private:
|
||||||
void run_arm_detection();
|
void run_arm_detection();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,11 +32,14 @@
|
|||||||
static double UpdateDelta();
|
static double UpdateDelta();
|
||||||
|
|
||||||
static GLFWwindow* window;
|
static GLFWwindow* window;
|
||||||
|
computervision::AsyncArmDetection as;
|
||||||
|
computervision::OpenPoseVideo openPoseVideo;
|
||||||
|
|
||||||
void retrieve_points(std::vector<Point> arm_points)
|
void retrieve_points(std::vector<Point> arm_points)
|
||||||
{
|
{
|
||||||
std::cout << "got points!!" << std::endl;
|
std::cout << "got points!!" << std::endl;
|
||||||
std::cout << "points: " << arm_points << std::endl;
|
std::cout << "points: " << arm_points << std::endl;
|
||||||
|
as.start(retrieve_points, openPoseVideo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -76,7 +79,7 @@ int main(void)
|
|||||||
// create object detection object instance
|
// create object detection object instance
|
||||||
computervision::ObjectDetection objDetect;
|
computervision::ObjectDetection objDetect;
|
||||||
//computervision::OpenPoseImage openPoseImage;
|
//computervision::OpenPoseImage openPoseImage;
|
||||||
computervision::OpenPoseVideo openPoseVideo;
|
|
||||||
openPoseVideo.setup();
|
openPoseVideo.setup();
|
||||||
|
|
||||||
|
|
||||||
@@ -87,8 +90,8 @@ int main(void)
|
|||||||
|
|
||||||
//openPoseVideo.setup();
|
//openPoseVideo.setup();
|
||||||
|
|
||||||
computervision::AsyncArmDetection as;
|
|
||||||
as.start(retrieve_points, objDetect.getCap(),openPoseVideo);
|
as.start(retrieve_points, openPoseVideo);
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
<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" />
|
||||||
|
<ClCompile Include="src\computervision\VideoCapture.cpp" />
|
||||||
<ClCompile Include="src\entities\camera.cpp" />
|
<ClCompile Include="src\entities\camera.cpp" />
|
||||||
<ClCompile Include="src\entities\entity.cpp" />
|
<ClCompile Include="src\entities\entity.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
<ClInclude Include="src\computervision\OpenPoseVideo.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\computervision\VideoCapture.h" />
|
||||||
<ClInclude Include="src\entities\camera.h" />
|
<ClInclude Include="src\entities\camera.h" />
|
||||||
<ClInclude Include="src\entities\entity.h" />
|
<ClInclude Include="src\entities\entity.h" />
|
||||||
<ClInclude Include="src\models\model.h" />
|
<ClInclude Include="src\models\model.h" />
|
||||||
|
|||||||
@@ -63,6 +63,9 @@
|
|||||||
<ClCompile Include="src\computervision\async\async_arm_detection.cpp">
|
<ClCompile Include="src\computervision\async\async_arm_detection.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\computervision\VideoCapture.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\entities\Camera.h">
|
<ClInclude Include="src\entities\Camera.h">
|
||||||
@@ -116,6 +119,9 @@
|
|||||||
<ClInclude Include="src\computervision\async\async_arm_detection.h">
|
<ClInclude Include="src\computervision\async\async_arm_detection.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\computervision\VideoCapture.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Xml Include="res\haarcascade_frontalface_alt.xml" />
|
<Xml Include="res\haarcascade_frontalface_alt.xml" />
|
||||||
|
|||||||
Reference in New Issue
Block a user