diff --git a/Sources/src/Visnode/main.cpp b/Sources/src/Visnode/main.cpp index 62da68c..8cf2dbf 100644 --- a/Sources/src/Visnode/main.cpp +++ b/Sources/src/Visnode/main.cpp @@ -29,30 +29,23 @@ SerialPortManager::init(); ui::UiController::exitCalled = false; ui::UiController::runIntro = false; int i = 0,count = 1; -_Float64 avgr=0,avgl=0; +_Float64 avgr=0; while(!ui::UiController::exitCalled){ #ifdef DBGMODE auto start = std::chrono::steady_clock::now(); #endif - std::future uiL = std::async (ui::UiDrawer::drawUiL); - std::future uiR = std::async (ui::UiDrawer::drawUiR); - uiL.get(); + std::future uiF = std::async (ui::UiDrawer::drawUi); + uiF.get(); #ifdef DBGMODE auto end1 = since(start).count(); #endif - uiR.get(); #ifdef DBGMODE - auto end2 = since(start).count(); - #endif - #ifdef DBGMODE - std::cout << "Elapsed(ms)=" << end1 << "," << end2 << std::endl; + std::cout << "Elapsed(ms)=" << end1 << std::endl; if(avgr == 0){ avgr = end1; - avgl = end2; }else{ avgr = (avgr+end1)/count; - avgl = (avgl+end2)/count; } if(i > 100){ diff --git a/Sources/src/Visnode/prog b/Sources/src/Visnode/prog index 88d2e2e..41a3898 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 b71bdf9..7dcfb59 100644 --- a/Sources/src/Visnode/threadweaver/debugging.hpp +++ b/Sources/src/Visnode/threadweaver/debugging.hpp @@ -1,6 +1,13 @@ #include #include -#define DBGMODE +//#define DBGMODE +#define DBGCOMM + +#ifdef DBGMODE +#define DEBUG_LOG(x) std::cout << x << std::endl; +#else +#define DEBUG_LOG(x) +#endif //#define DBGPRINT(x) do { if (DBGMODE) { std::cerr << x << std::endl; }} while (0) \ No newline at end of file diff --git a/Sources/src/Visnode/ui/_ui.hpp b/Sources/src/Visnode/ui/_ui.hpp index ef02602..3f2999f 100644 --- a/Sources/src/Visnode/ui/_ui.hpp +++ b/Sources/src/Visnode/ui/_ui.hpp @@ -8,11 +8,12 @@ #include "../cameras/_cam.hpp" #include "../psvr/_psvr.hpp" #include +#include -#define DEFAULT_UI_WINDOW_AMOUNT 2 //2 windows, one for each eye -#define DEFAULT_UI_OFFSET_X 0 //1080 +#define DEFAULT_UI_WINDOW_AMOUNT 1 //2 windows, one for each eye +#define DEFAULT_UI_OFFSET_X 1080 //1080 #define DEFAULT_UI_OFFSET_Y 0 -#define DEFAULT_UI_SIZE_X 960 //psvr is 960x1080 per eye +#define DEFAULT_UI_SIZE_X 1920 //psvr is 960x1080 per eye #define DEFAULT_UI_SIZE_Y 1080 int runtest(); @@ -31,8 +32,7 @@ namespace ui { }; class UiDrawer{ //drawer is static because we only ever need one public: - static void drawUiR(); - static void drawUiL(); + static void drawUi(); static void drawStartupSequence(); static void drawMenu(); static Mat OverlayMat; //drawn at each frame diff --git a/Sources/src/Visnode/ui/uiDrawer.cpp b/Sources/src/Visnode/ui/uiDrawer.cpp index c77222e..886506f 100644 --- a/Sources/src/Visnode/ui/uiDrawer.cpp +++ b/Sources/src/Visnode/ui/uiDrawer.cpp @@ -9,45 +9,37 @@ std::mutex ui::UiDrawer::OsMatLock; namespace ui{ //draws the UI for the left screen of the psvr - void UiDrawer::drawUiL(){ - Mat UiMat = prepareUiMat(); //prepare black background + void UiDrawer::drawUi(){ + Mat UiMat = prepareUiMat(); //prepare black background 960*1080 + DEBUG_LOG("prepared UI mat") cameraManager::accessLocks[0]->lock(); //lock the capture access - Mat surface = cameraManager::captures[0]; //retreive latest camera frame + Mat cameraFrame = cameraManager::captures[0]; //retreive latest camera frame cameraManager::accessLocks[0]->unlock(); //unlock capture access - if(surface.rows <= 0 || surface.cols <= 0) return; //check for empty frame - surface = resizeIn(surface); //resize the frame to the standard format + DEBUG_LOG("retreived camera frame") + if(cameraFrame.rows <= 0 || cameraFrame.cols <= 0) return; //check for empty frame + cameraFrame = resizeIn(cameraFrame); //resize the frame to the standard format + DEBUG_LOG("resized camera frame") //Copy the frame in the center of the background - surface.copyTo(UiMat(cv::Rect((UiMat.cols/2)-(surface.cols/2),(UiMat.rows/2)-(surface.rows/2),surface.cols, surface.rows))); + cameraFrame.copyTo(UiMat(cv::Rect((UiMat.cols/2)-(cameraFrame.cols/2),(UiMat.rows/2)-(cameraFrame.rows/2),cameraFrame.cols, cameraFrame.rows))); + DEBUG_LOG("copied camera frame") UiMat = OverlayBlackMask(UiMat, OverlayMat); //add the fixed overlay + DEBUG_LOG("overlayed camera frame") if(UiController::showMenu){ UiDrawer::drawMenu(); OsMatLock.lock(); - UiMat = OverlayBlackMask(UiMat, OsMat, ui::UiController::menuPos.x,ui::UiController::menuPos.y); //add the OS ui overlay + //UiMat = OverlayBlackMask(UiMat, OsMat, ui::UiController::menuPos.x,ui::UiController::menuPos.y); //add the OS ui overlay + UiMat = OverlayBlackMask(UiMat, OsMat); OsMatLock.unlock(); } - UiManager::managedUIs[0]->drawSurface = UiMat; //write the final image to the psvr UI buffer + DEBUG_LOG("drawn menu") + Mat finished(cv::Size(1920, 1080), CV_8UC3,Scalar(0,0,0));; + Mat mats[] = {UiMat,UiMat}; + cv::hconcat(mats,2,finished); + DEBUG_LOG("concated mats") + UiManager::managedUIs[0]->drawSurface = finished; //write the final image to the psvr UI buffer UiManager::managedUIs[0]->draw(); //send the image to the psvr } - void UiDrawer::drawUiR(){ - Mat UiMat = prepareUiMat(); - cameraManager::accessLocks[0]->lock(); - Mat surface = cameraManager::captures[0]; - cameraManager::accessLocks[0]->unlock(); - if(surface.rows <= 0 || surface.cols <= 0) return; - surface = resizeIn(surface); - surface.copyTo(UiMat(cv::Rect((UiMat.cols/2)-(surface.cols/2),(UiMat.rows/2)-(surface.rows/2),surface.cols, surface.rows))); - UiMat = OverlayBlackMask(UiMat, OverlayMat); - if(UiController::showMenu){ - UiDrawer::drawMenu(); - OsMatLock.lock(); - UiMat = OverlayBlackMask(UiMat, OsMat, ui::UiController::menuPos.x,ui::UiController::menuPos.y); //add the OS ui overlay - OsMatLock.unlock(); - } - UiManager::managedUIs[1]->drawSurface = UiMat; - UiManager::managedUIs[1]->draw(); - } - void UiDrawer::drawStartupSequence(){ cout << "opening external ressources" << endl; VideoCapture cap("./media/hud_startup.gif"); @@ -64,7 +56,6 @@ namespace ui{ { frame = OverlayBlackMask(frame, overlay); imshow(ui::UiManager::managedUIs.at(0)->myWindow, frame); - imshow(ui::UiManager::managedUIs.at(1)->myWindow, frame); if(waitKey(30) >= 0) break; } cap.release(); @@ -102,7 +93,10 @@ namespace ui{ ///if a non transparent picture is supplied (3 channels), it will be made transparent by using black as a mask Mat UiDrawer::OverlayBlackMask(Mat input, Mat toOverlay, int x, int y){ //return input; - if(input.cols < toOverlay.cols || input.rows < toOverlay.rows) return input; + if(input.cols < toOverlay.cols || input.rows < toOverlay.rows){ + cerr << "Wrong size for inout file!!! overlay was bigger" << endl; + return input; + } Mat toOverlayGRAY, mask; vector Bands; diff --git a/Sources/src/Visnode/ui/uiManager.cpp b/Sources/src/Visnode/ui/uiManager.cpp index d70ff98..e03aa2d 100644 --- a/Sources/src/Visnode/ui/uiManager.cpp +++ b/Sources/src/Visnode/ui/uiManager.cpp @@ -14,6 +14,7 @@ namespace ui{ namedWindow(newUI->myWindow); 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); cout << "window: " << newUI->myWindow << " created at " << DEFAULT_UI_OFFSET_X+i*960 << " , " << DEFAULT_UI_OFFSET_Y << endl;