diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index a975c51..1395183 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -1,17 +1,15 @@ - -#include #include -#include #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); diff --git a/src/computervision/VideoCapture.cpp b/src/computervision/VideoCapture.cpp new file mode 100644 index 0000000..52b6184 --- /dev/null +++ b/src/computervision/VideoCapture.cpp @@ -0,0 +1,11 @@ +#include "VideoCapture.h" + +namespace videocapture{ + static cv::VideoCapture cap(1); + + cv::VideoCapture getCap() { + cap.release(); + + return cap; + } +} diff --git a/src/computervision/VideoCapture.h b/src/computervision/VideoCapture.h new file mode 100644 index 0000000..85f5bc5 --- /dev/null +++ b/src/computervision/VideoCapture.h @@ -0,0 +1,8 @@ +#pragma once +#include +#include +#include + +namespace videocapture { + cv::VideoCapture getCap(); +} diff --git a/src/computervision/async/async_arm_detection.cpp b/src/computervision/async/async_arm_detection.cpp index 6b27611..6d0dc29 100644 --- a/src/computervision/async/async_arm_detection.cpp +++ b/src/computervision/async/async_arm_detection.cpp @@ -2,6 +2,7 @@ #include "async_arm_detection.h" #include "../OpenPoseVideo.h" #include +#include "../VideoCapture.h" namespace computervision @@ -16,28 +17,28 @@ namespace computervision } - void AsyncArmDetection::start(std::function)> points_ready_func, cv::VideoCapture cap, OpenPoseVideo op) + void AsyncArmDetection::start(std::function)> points_ready_func, OpenPoseVideo op) { - auto lambda = [](std::function)> f, cv::VideoCapture c, OpenPoseVideo op) { + auto lambda = [](std::function)> 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); } } diff --git a/src/computervision/async/async_arm_detection.h b/src/computervision/async/async_arm_detection.h index 6d7572a..5d5e11b 100644 --- a/src/computervision/async/async_arm_detection.h +++ b/src/computervision/async/async_arm_detection.h @@ -14,7 +14,7 @@ namespace computervision AsyncArmDetection(void); - void start(std::function)>, cv::VideoCapture cap, computervision::OpenPoseVideo op); + void start(std::function)>, computervision::OpenPoseVideo op); private: void run_arm_detection(); }; diff --git a/src/main.cpp b/src/main.cpp index a14dd84..f1f98ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 098b361..269888f 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -26,6 +26,7 @@ + @@ -44,6 +45,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index eda7a9e..9a0bd1a 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -63,6 +63,9 @@ Source Files + + Source Files + @@ -116,6 +119,9 @@ Header Files + + Header Files +