From 1a149b8b7e649beb310a581ee11466f7b212fee5 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 2 Jun 2021 10:05:09 +0200 Subject: [PATCH] [ADD] static camera instance --- src/computervision/ObjectDetection.cpp | 4 +++- src/computervision/ObjectDetection.h | 1 + src/computervision/async/StaticCameraInstance.h | 12 ++++++++++++ src/computervision/async/async_arm_detection.cpp | 6 +++--- src/computervision/async/async_arm_detection.h | 1 + src/main.cpp | 2 -- wk2_fps.vcxproj | 1 + wk2_fps.vcxproj.filters | 3 +++ 8 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/computervision/async/StaticCameraInstance.h diff --git a/src/computervision/ObjectDetection.cpp b/src/computervision/ObjectDetection.cpp index a975c51..dc405ac 100644 --- a/src/computervision/ObjectDetection.cpp +++ b/src/computervision/ObjectDetection.cpp @@ -8,10 +8,10 @@ #include "SkinDetector.h" #include "FaceDetector.h" #include "FingerCount.h" +#include "async/StaticCameraInstance.h" namespace computervision { - cv::VideoCapture cap(0); cv::Mat img, imgGray, img2, img2Gray, img3, img4; @@ -24,6 +24,8 @@ namespace computervision FaceDetector faceDetector; FingerCount fingerCount; + cv::VideoCapture cap = computervision_async::getCap(); + ObjectDetection::ObjectDetection() { } diff --git a/src/computervision/ObjectDetection.h b/src/computervision/ObjectDetection.h index 14c2c3d..45f4c6d 100644 --- a/src/computervision/ObjectDetection.h +++ b/src/computervision/ObjectDetection.h @@ -65,6 +65,7 @@ namespace computervision */ bool drawHandMaskRect(cv::Mat *input); + cv::VideoCapture getCap(); }; diff --git a/src/computervision/async/StaticCameraInstance.h b/src/computervision/async/StaticCameraInstance.h new file mode 100644 index 0000000..625d478 --- /dev/null +++ b/src/computervision/async/StaticCameraInstance.h @@ -0,0 +1,12 @@ +#pragma once +#include + +namespace static_camera +{ + + static cv::VideoCapture getCap() + { + static cv::VideoCapture cap(0); + return cap; + } +}; diff --git a/src/computervision/async/async_arm_detection.cpp b/src/computervision/async/async_arm_detection.cpp index 6b27611..2557e6e 100644 --- a/src/computervision/async/async_arm_detection.cpp +++ b/src/computervision/async/async_arm_detection.cpp @@ -21,12 +21,12 @@ namespace computervision auto lambda = [](std::function)> f, cv::VideoCapture c, OpenPoseVideo op) { std::cout << "STARTING THREAD LAMBDA" << std::endl; - cv::VideoCapture cap(0); + cv::VideoCapture cap = computervision_async::getCap(); if (!cap.isOpened()) { - std::cout << "error opening video" << std::endl; - return; + std::cout << "capture was closed, opening..." << std::endl; + cap.open(0); } while (true) diff --git a/src/computervision/async/async_arm_detection.h b/src/computervision/async/async_arm_detection.h index 6d7572a..a265ce6 100644 --- a/src/computervision/async/async_arm_detection.h +++ b/src/computervision/async/async_arm_detection.h @@ -4,6 +4,7 @@ #include #include #include "../OpenPoseVideo.h" +#include "StaticCameraInstance.h" namespace computervision diff --git a/src/main.cpp b/src/main.cpp index a14dd84..00492e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,8 +85,6 @@ int main(void) cv::Mat cameraFrame; - //openPoseVideo.setup(); - computervision::AsyncArmDetection as; as.start(retrieve_points, objDetect.getCap(),openPoseVideo); diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 5f36c6f..ddc8113 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -38,6 +38,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index 0986f9d..a15b786 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -116,6 +116,9 @@ Header Files + + Header Files +