[BUG] image still doesnt work

This commit is contained in:
Jasper
2021-05-28 16:49:13 +02:00
parent 40529f84b3
commit 9d80cddbd1
8 changed files with 43 additions and 22 deletions

View File

@@ -1,17 +1,15 @@
#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 "VideoCapture.h"
using namespace videocapture;
namespace computervision
{
cv::VideoCapture cap(0);
cv::Mat img, imgGray, img2, img2Gray, img3, img4;
@@ -29,15 +27,10 @@ namespace computervision
}
cv::Mat ObjectDetection::readCamera() {
cap.read(img);
videocapture::getCap().read(img);
return img;
}
cv::VideoCapture ObjectDetection::getCap()
{
return cap;
}
bool ObjectDetection::detectHand(Mat cameraFrame)
{
Mat inputFrame = generateHandMaskSquare(cameraFrame);
@@ -81,8 +74,8 @@ namespace computervision
void ObjectDetection::calculateDifference()
{
cap.read(img);
cap.read(img2);
videocapture::getCap().read(img);
videocapture::getCap().read(img2);
cv::cvtColor(img, imgGray, cv::COLOR_RGBA2GRAY);
cv::cvtColor(img2, img2Gray, cv::COLOR_RGBA2GRAY);

View File

@@ -0,0 +1,11 @@
#include "VideoCapture.h"
namespace videocapture{
static cv::VideoCapture cap(1);
cv::VideoCapture getCap() {
cap.release();
return cap;
}
}

View File

@@ -0,0 +1,8 @@
#pragma once
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
namespace videocapture {
cv::VideoCapture getCap();
}

View File

@@ -2,6 +2,7 @@
#include "async_arm_detection.h"
#include "../OpenPoseVideo.h"
#include <thread>
#include "../VideoCapture.h"
namespace computervision
@@ -16,28 +17,28 @@ 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 = [](std::function<void(std::vector<Point>)> f, OpenPoseVideo op) {
std::cout << "STARTING THREAD LAMBDA" << std::endl;
cv::VideoCapture cap(0);
if (!cap.isOpened())
if (!videocapture::getCap().isOpened())
{
std::cout << "error opening video" << std::endl;
videocapture::getCap().open(1);
return;
}
Mat img;
while (true)
{
Mat img;
cap.read(img);
videocapture::getCap().read(img);
imshow("image", img);
op.movementSkeleton(img, f);
}
};
std::cout << "starting function" << std::endl;
std::thread async_arm_detect_thread(lambda, points_ready_func, cap, op);
std::thread async_arm_detect_thread(lambda, points_ready_func, op);
}
}

View File

@@ -14,7 +14,7 @@ namespace computervision
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:
void run_arm_detection();
};

View File

@@ -88,7 +88,7 @@ int main(void)
//openPoseVideo.setup();
computervision::AsyncArmDetection as;
as.start(retrieve_points, objDetect.getCap(),openPoseVideo);
as.start(retrieve_points, openPoseVideo);
// Main game loop

View File

@@ -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" />
@@ -44,6 +45,7 @@
<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" />

View File

@@ -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,6 +119,9 @@
<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" />