diff --git a/Sources/src/Visnode/cameras/CMakeLists.txt b/Sources/src/Visnode/cameras/CMakeLists.txt index 2dcac43..c81ec01 100644 --- a/Sources/src/Visnode/cameras/CMakeLists.txt +++ b/Sources/src/Visnode/cameras/CMakeLists.txt @@ -15,4 +15,5 @@ find_package( OpenCV REQUIRED ) target_link_libraries(cameras ${OpenCV_LIBS}) target_link_libraries(cameras threadweaver) +target_link_libraries(cameras perfcheckers) MESSAGE(STATUS "Done building cameras") \ No newline at end of file diff --git a/Sources/src/Visnode/cameras/_cam.hpp b/Sources/src/Visnode/cameras/_cam.hpp index 65b46b9..ce4420d 100644 --- a/Sources/src/Visnode/cameras/_cam.hpp +++ b/Sources/src/Visnode/cameras/_cam.hpp @@ -14,6 +14,7 @@ #include #include #include "../threadweaver/threadweaver.hpp" +#include "../perfcheckers/framerate.hpp" #define DEBUG_ELAPSED_START std::chrono::steady_clock::time_point bgd = std::chrono::steady_clock::now(); #define DEBUG_ELAPSED_END std::chrono::steady_clock::time_point bge = std::chrono::steady_clock::now(); diff --git a/Sources/src/Visnode/cameras/cameraManager.cpp b/Sources/src/Visnode/cameras/cameraManager.cpp index 965d565..db8f6d7 100644 --- a/Sources/src/Visnode/cameras/cameraManager.cpp +++ b/Sources/src/Visnode/cameras/cameraManager.cpp @@ -7,6 +7,7 @@ std::vector cameraManager::accessLocks; void cameraManager::runCaptureForCamera(camera* c, uint index){ while(runCaptureThread){ + fcheckManager::fcCam.tickBegin(); if(!c->source->isOpened()){ cout << "camera " << c->path << " is closed, opening..." << endl; if(!c->source->open(c->path,cv::CAP_ANY)){ @@ -23,6 +24,7 @@ void cameraManager::runCaptureForCamera(camera* c, uint index){ } else { cout << "read error grabbing from camera " << c->path << endl; } + fcheckManager::fcCam.tickUpdate(); } } diff --git a/Sources/src/Visnode/perfcheckers/CMakeLists.txt b/Sources/src/Visnode/perfcheckers/CMakeLists.txt index a647766..e65e7a3 100644 --- a/Sources/src/Visnode/perfcheckers/CMakeLists.txt +++ b/Sources/src/Visnode/perfcheckers/CMakeLists.txt @@ -1,5 +1,6 @@ set(perfcheckers_source_files framerate.cpp + fcheckManager.cpp framerate.hpp ) MESSAGE(STATUS "Building perfcheckers") diff --git a/Sources/src/Visnode/perfcheckers/fcheckManager.cpp b/Sources/src/Visnode/perfcheckers/fcheckManager.cpp new file mode 100644 index 0000000..40d5876 --- /dev/null +++ b/Sources/src/Visnode/perfcheckers/fcheckManager.cpp @@ -0,0 +1,5 @@ +#include "framerate.hpp" + +framerateChecker fcheckManager::fcUI; +framerateChecker fcheckManager::fcShow; +framerateChecker fcheckManager::fcCam; \ No newline at end of file diff --git a/Sources/src/Visnode/perfcheckers/framerate.hpp b/Sources/src/Visnode/perfcheckers/framerate.hpp index fee7b08..a4423e0 100644 --- a/Sources/src/Visnode/perfcheckers/framerate.hpp +++ b/Sources/src/Visnode/perfcheckers/framerate.hpp @@ -1,5 +1,6 @@ #include +#include class framerateChecker{ private: @@ -7,9 +8,16 @@ class framerateChecker{ public: std::time_t tBegin, tEnd; - int tick, fps = 0; + std::atomic tick,fps = 0; long frameCounter = 0; void tickBegin(); void tickUpdate(); +}; + +class fcheckManager{ + public: + static framerateChecker fcUI; + static framerateChecker fcShow; + static framerateChecker fcCam; }; \ No newline at end of file diff --git a/Sources/src/Visnode/prog b/Sources/src/Visnode/prog index 485c6c6..556a14b 100755 Binary files a/Sources/src/Visnode/prog and b/Sources/src/Visnode/prog differ diff --git a/Sources/src/Visnode/threadweaver/debugging.hpp b/Sources/src/Visnode/threadweaver/debugging.hpp index 390da9b..8c7ff1a 100644 --- a/Sources/src/Visnode/threadweaver/debugging.hpp +++ b/Sources/src/Visnode/threadweaver/debugging.hpp @@ -3,6 +3,7 @@ //#define DBGMODE #define DBGCOMM +#define OGLWIN #ifdef DBGMODE #define DEBUG_LOG(x) std::cout << "-DEBUG: " << x << std::endl; diff --git a/Sources/src/Visnode/ui/CMakeLists.txt b/Sources/src/Visnode/ui/CMakeLists.txt index 3ac34ff..9cfda5e 100644 --- a/Sources/src/Visnode/ui/CMakeLists.txt +++ b/Sources/src/Visnode/ui/CMakeLists.txt @@ -19,7 +19,6 @@ add_library(ui ${ui_source_files}) target_link_libraries(ui ${OpenCV_LIBS}) target_link_libraries(ui psvr) -target_link_libraries(ui perfcheckers) target_link_libraries(ui cameras) MESSAGE(STATUS "Done building ui") \ No newline at end of file diff --git a/Sources/src/Visnode/ui/_ui.hpp b/Sources/src/Visnode/ui/_ui.hpp index e2e7e52..df1311a 100644 --- a/Sources/src/Visnode/ui/_ui.hpp +++ b/Sources/src/Visnode/ui/_ui.hpp @@ -5,11 +5,11 @@ #include #include -#include "../perfcheckers/framerate.hpp" #include "../cameras/_cam.hpp" #include "../psvr/_psvr.hpp" #include #include +#include #define DEFAULT_UI_WINDOW_AMOUNT 1 //2 windows, one for each eye #define DEFAULT_UI_OFFSET_X 1080 //1080 @@ -21,6 +21,7 @@ int runtest(); using namespace std; using namespace cv; +using namespace cv::ogl; using namespace psvr; namespace ui { @@ -29,6 +30,7 @@ namespace ui { public: UMat drawBuffer; UMat drawSurface; //Current frame + cv::ogl::Texture2D drawTexture; int id; std::string myWindow; void draw(); @@ -39,8 +41,9 @@ namespace ui { static void drawStartupSequence(); static void drawMenu(); static void runDrawUi(); - static UMat OverlayMat; //drawn at each frame - static UMat OsMat; //drawn on certain events + static UMat OverlayMat; //drawn at each frame (screen) + static UMat OsMat; //drawn on certain events (menu) + static cv::ogl::Texture2D OvTexture; static std::mutex OsMatLock; private: static framerateChecker* fpsCounter; diff --git a/Sources/src/Visnode/ui/ui.cpp b/Sources/src/Visnode/ui/ui.cpp index c5fec5d..6cc5bdc 100644 --- a/Sources/src/Visnode/ui/ui.cpp +++ b/Sources/src/Visnode/ui/ui.cpp @@ -1,12 +1,18 @@ #include "_ui.hpp" void ui::Ui::draw(){ - if(drawSurface.empty()) + fcheckManager::fcShow.tickBegin(); + if(drawSurface.empty()){ + //fcheckManager::fcShow.fps = 0; return; + } UiManager::accessLocks.at(this->id)->lock(); drawBuffer = drawSurface; - UiManager::accessLocks.at(this->id)->unlock(); + UiManager::accessLocks.at(this->id)->unlock(); + //drawTexture = cv::ogl::Texture2D(drawBuffer); + //cv::ogl::convertToGLTexture2D(drawBuffer, drawTexture); imshow(this->myWindow, this->drawBuffer); - waitKey(17); + waitKey(1); + fcheckManager::fcShow.tickUpdate(); } \ No newline at end of file diff --git a/Sources/src/Visnode/ui/uiDrawer.cpp b/Sources/src/Visnode/ui/uiDrawer.cpp index 06808a7..218e047 100644 --- a/Sources/src/Visnode/ui/uiDrawer.cpp +++ b/Sources/src/Visnode/ui/uiDrawer.cpp @@ -1,6 +1,7 @@ #include "_ui.hpp" UMat ui::UiDrawer::OverlayMat; UMat ui::UiDrawer::OsMat; //drawn on certain events +cv::ogl::Texture2D OvTexture; std::mutex ui::UiDrawer::OsMatLock; framerateChecker* ui::UiDrawer::fpsCounter = new framerateChecker(); @@ -11,7 +12,7 @@ framerateChecker* ui::UiDrawer::fpsCounter = new framerateChecker(); namespace ui{ //draws the UI for the left screen of the psvr void UiDrawer::drawUi(){ - fpsCounter->tickBegin(); + fcheckManager::fcUI.tickBegin(); UMat UiMat = prepareUiMat(); //prepare black background 960*1080 DEBUG_LOG("prepared UI mat") cameraManager::accessLocks[0]->lock(); //lock the capture access @@ -43,7 +44,7 @@ namespace ui{ UiManager::accessLocks.at(0)->lock(); UiManager::managedUIs[0]->drawSurface = finished; //write the final image to the psvr UI buffer UiManager::accessLocks.at(0)->unlock(); - fpsCounter->tickUpdate(); + fcheckManager::fcUI.tickUpdate(); } void UiDrawer::drawStartupSequence(){ @@ -58,10 +59,18 @@ namespace ui{ return; } UMat frame; + #ifdef OGLWIN + cv::ogl::Texture2D frameOGL = Texture2D(); + #endif while(cap.read(frame)) { frame = OverlayBlackMask(frame, overlay); - imshow(ui::UiManager::managedUIs.at(0)->myWindow, frame); +#ifdef OGLWIN + frameOGL.copyFrom(frame); + cv::imshow(ui::UiManager::managedUIs.at(0)->myWindow, frameOGL); +#else + cv::imshow(ui::UiManager::managedUIs.at(0)->myWindow, frame); +#endif if(waitKey(30) >= 0) break; } cap.release(); @@ -81,7 +90,14 @@ namespace ui{ std::string str = iter->first; cv::putText(MenuMat, str, Point2i(5,stackerIndex+=20), HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255,255,255), 1, 8, false); } - //cv::putText(MenuMat, cv::format("Frames per second: %d - %ld", fpsCounter->fps, fpsCounter->frameCounter), Point2i(5,stackerIndex+=20), HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255,255,255), 1, 8, false); + int uiFps,Drawfps,camFPS = 0; + uiFps = fcheckManager::fcUI.fps; + Drawfps = fcheckManager::fcShow.fps; + camFPS = fcheckManager::fcCam.fps; + cv::putText(MenuMat, cv::format("Eps Ui drawer: %d", uiFps), Point2i(5,stackerIndex+=20), HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255,255,255), 1, 8, false); + cv::putText(MenuMat, cv::format("Eps imshow: %d", Drawfps), Point2i(5,stackerIndex+=20), HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255,255,255), 1, 8, false); + cv::putText(MenuMat, cv::format("Eps Camera 0: %d", camFPS), Point2i(5,stackerIndex+=20), HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255,255,255), 1, 8, false); + cv::rectangle(MenuMat, cv::Rect2i(0,((20*ui::UiController::selectedIndex)+20)+5,wd, 20), Scalar(200,0,0), 3, 8, 0); OsMatLock.lock(); OsMat = MenuMat; diff --git a/Sources/src/Visnode/ui/uiManager.cpp b/Sources/src/Visnode/ui/uiManager.cpp index 52e9784..2de95fa 100644 --- a/Sources/src/Visnode/ui/uiManager.cpp +++ b/Sources/src/Visnode/ui/uiManager.cpp @@ -20,11 +20,19 @@ namespace ui{ Ui* newUI = new Ui(); cout << "creating UI n°" << to_string(i) << endl; newUI->myWindow = "project- UI"+std::to_string(i); - - namedWindow(newUI->myWindow); + #ifdef OGLWIN + DEBUG_LOG("created opengl window") + namedWindow(newUI->myWindow,WINDOW_OPENGL); + #else + DEBUG_LOG("created cpu-based window") + namedWindow(newUI->myWindow); + #endif moveWindow(newUI->myWindow,DEFAULT_UI_OFFSET_X+i*960,DEFAULT_UI_OFFSET_Y); resizeWindow(newUI->myWindow,DEFAULT_UI_SIZE_X,DEFAULT_UI_SIZE_Y); - setWindowProperty(newUI->myWindow, cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN); + //setWindowProperty(newUI->myWindow, cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN); + #ifdef OGLWIN + cv::setOpenGlContext(newUI->myWindow); + #endif cout << "window: " << newUI->myWindow << " created at " << DEFAULT_UI_OFFSET_X+i*960 << " , " << DEFAULT_UI_OFFSET_Y << endl;