debugged issues, added exception handling to ui drawer

opengl
yorick 3 years ago
parent 79f5e84409
commit 0443cd4b5f

@ -9,7 +9,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-Ofast")
project(visnode)
#set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/../bin)
set(CMAKE_BINARY_DIR /home/kanken/code/project-/Sources/src/Visnode/)
set(CMAKE_BINARY_DIR /home/kanken/code/ARHS_core/Sources/src/Visnode)
find_package(OpenCV REQUIRED)
find_package(TBB REQUIRED)
@ -24,6 +24,7 @@ MESSAGE(STATUS "Opencv_LINK_DIRS : ${Opencv_LINK_DIRS}")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
add_subdirectory(perfcheckers)
add_subdirectory(threadweaver)
add_subdirectory(ihidapi)
add_subdirectory(cameras)

@ -1,5 +1,5 @@
#include "_cam.hpp"
#include <signal.h>
vector<camera*> cameraManager::videoSources;
std::vector<UMat> cameraManager::captures;
bool cameraManager::runCaptureThread;
@ -39,7 +39,7 @@ int cameraManager::init(){
VideoCapture vs(camID);
if(!vs.isOpened() && !vs.open(camID))
{
cout << "opening camera " << camIdx << " failed" <<endl;
cout << "\x1B[31opening camera " << camIdx << " failed\033[0m" <<endl;
vs.release();
}else{
vs.release();
@ -62,7 +62,7 @@ int cameraManager::init(){
}
void cameraManager::runCapture(){
cout << "enabling capture thread for " << videoSources.size() << " cameras" << endl;
cout << "cameraManager::runCapture------------------------------------------------\n" << "enabling capture thread for " << videoSources.size() << " cameras" << endl;
uint i = 0;
runCaptureThread = true;
for(camera* c : videoSources){
@ -73,7 +73,7 @@ void cameraManager::runCapture(){
std::thread* t = new std::thread(cameraManager::runCaptureForCamera,c,i);
i++;
cout << "moving thread" << endl;
Threadweaver::stick_this_thread_to_core(t,i+1);
Threadweaver::stick_this_thread_to_core(t,2);
Threadweaver::captureThreads.push_back(t);
cout << "done" << endl;
}

@ -5,6 +5,7 @@ using namespace psvr;
int main(int argc, char* argv[])
{
try{
unsigned num_cpus = std::thread::hardware_concurrency();
cout << num_cpus <<" cores detected" << endl;
std::cout << cv::getBuildInformation() << std::endl;
@ -25,14 +26,20 @@ SerialPortManager::init();
ui::UiController::exitCalled = false;
ui::UiController::runIntro = false;
std::thread* t = new std::thread(ui::UiDrawer::runDrawUi);
Threadweaver::stick_this_thread_to_core(t,1);
Threadweaver::gfxPipelineThread = t;
DEBUG_LOG("Entering sleep while")
while(!ui::UiController::exitCalled){
sleep(5);
}
}
catch(...){
cerr << "caught maint thread exception" << endl;
}
DEBUG_LOG("Exitted sleep while")
Threadweaver::gfxPipelineThread->join();
return 0;

@ -0,0 +1,8 @@
set(perfcheckers_source_files
framerate.cpp
framerate.hpp
)
MESSAGE(STATUS "Building perfcheckers")
add_library(perfcheckers ${perfcheckers_source_files})
MESSAGE(STATUS "Done building perfcheckers")

@ -0,0 +1,19 @@
#include "framerate.hpp"
void framerateChecker::tickBegin(){
if(hasBegun) return;
tBegin = std::time(0);
hasBegun = true;
tick = 0;
fps = 0;
}
void framerateChecker::tickUpdate(){
frameCounter++;
tEnd = std::time(0) - tBegin;
if(tEnd - tick < 1) return;
tick++;
fps = frameCounter;
frameCounter = 0;
}

@ -0,0 +1,15 @@
#include <ctime>
class framerateChecker{
private:
bool hasBegun = false;
public:
std::time_t tBegin, tEnd;
int tick, fps = 0;
long frameCounter = 0;
void tickBegin();
void tickUpdate();
};

Binary file not shown.

@ -5,7 +5,7 @@
#define DBGCOMM
#ifdef DBGMODE
#define DEBUG_LOG(x) std::cout << x << std::endl;
#define DEBUG_LOG(x) std::cout << "-DEBUG: " << x << std::endl;
#else
#define DEBUG_LOG(x)
#endif

@ -12,5 +12,5 @@ void Threadweaver::stick_this_thread_to_core(std::thread* t,int core_id){
CPU_ZERO(&cpuset);
CPU_SET(core_id, &cpuset);
int rc = pthread_setaffinity_np(t->native_handle(),sizeof(cpu_set_t), &cpuset);
std::cout << "set thread to core " << core_id << " successfully" << std::endl;
std::cout << "set thread to core " << core_id << " successfully" << std::endl;
}

@ -19,6 +19,7 @@ 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")

@ -5,6 +5,7 @@
#include <ctime>
#include <functional>
#include "../perfcheckers/framerate.hpp"
#include "../cameras/_cam.hpp"
#include "../psvr/_psvr.hpp"
#include <opencv2/imgcodecs/imgcodecs.hpp>
@ -42,6 +43,7 @@ namespace ui {
static UMat OsMat; //drawn on certain events
static std::mutex OsMatLock;
private:
static framerateChecker* fpsCounter;
static UMat prepareUiMat();
static UMat resizeIn(UMat input);
static UMat OverlayBlackMask(UMat input, UMat toOverlay, int x = 0, int y = 0);

@ -2,6 +2,7 @@
UMat ui::UiDrawer::OverlayMat;
UMat ui::UiDrawer::OsMat; //drawn on certain events
std::mutex ui::UiDrawer::OsMatLock;
framerateChecker* ui::UiDrawer::fpsCounter = new framerateChecker();
//UiMat = prepareUiMat();
//surface.copyTo(UiMat(cv::Rect((UiMat.cols/2)-(surface.cols/2),(UiMat.rows/2)-(surface.rows/2),surface.cols, surface.rows)));
@ -10,6 +11,7 @@ std::mutex ui::UiDrawer::OsMatLock;
namespace ui{
//draws the UI for the left screen of the psvr
void UiDrawer::drawUi(){
fpsCounter->tickBegin();
UMat UiMat = prepareUiMat(); //prepare black background 960*1080
DEBUG_LOG("prepared UI mat")
cameraManager::accessLocks[0]->lock(); //lock the capture access
@ -41,6 +43,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();
}
void UiDrawer::drawStartupSequence(){
@ -52,7 +55,7 @@ namespace ui{
ui::UiDrawer::OverlayMat = overlay;
if(!cap.isOpened()){
cout << "failed to open hud start media" << endl;
//return;
return;
}
UMat frame;
while(cap.read(frame))
@ -65,6 +68,7 @@ namespace ui{
}
void UiDrawer::drawMenu(){
try{
int& wd = UiController::menuSize.width;
int& he = UiController::menuSize.height;
unsigned int stackerIndex = 0;
@ -77,18 +81,29 @@ 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);
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;
OsMatLock.unlock();
} catch(...){
cerr << "\033[1;31m caught DrawUi::drawMenu thread exception \033[0m" << endl;
exit(1);
}
}
void UiDrawer::runDrawUi(){
try{
cout << "starting ui drawer thread" << endl;
ui::UiController::exitCalled = false;
while(!ui::UiController::exitCalled){
while(true){
DEBUG_LOG("drawing");
ui::UiDrawer::drawUi();
}
} catch(...){
cerr << "\033[1;31m caught DrawUi thread exception \033[0m" << endl;
exit(1);
}
}
UMat UiDrawer::prepareUiMat(){

Loading…
Cancel
Save