parent
a45f487aa8
commit
f25e211f6b
@ -1,12 +0,0 @@
|
||||
#include "helloLibrary/Class1.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace helloLibrary;
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
Class1 c("Hello World!");
|
||||
cout<<c.GetText()<<endl;
|
||||
return 0;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
build:
|
||||
cd ../../Documentation/Doxygen && doxygen Doxyfile
|
||||
|
||||
clean:
|
||||
rmdir /S /Q html
|
@ -1,7 +1,7 @@
|
||||
build :
|
||||
@mkdir -p $(CONFIG)
|
||||
build :
|
||||
@mkdir -p $(CONFIG)
|
||||
make -f makeprj.lnx CONFIG=$(CONFIG)
|
||||
|
||||
clean :
|
||||
make clean -f makeprj.lnx CONFIG=debug
|
||||
clean :
|
||||
make clean -f makeprj.lnx CONFIG=debug
|
||||
make clean -f makeprj.lnx CONFIG=release
|
@ -1,34 +1,34 @@
|
||||
CC = /usr/bin/g++
|
||||
CFLAGS = -c -Wall -ansi
|
||||
EXE = helloLibrary_Tests
|
||||
SUFFIX = d
|
||||
|
||||
ifeq (debug,$(CONFIG))
|
||||
CFLAGS += -O2 -DNDEBUG
|
||||
SUFFIX = d
|
||||
else
|
||||
CFLAGS += -g -D_DEBUG
|
||||
SUFFIX =
|
||||
endif
|
||||
|
||||
INCPATH = -I../../../../include
|
||||
SRCDIR = ../../../../Applications/Tests/helloLibrary
|
||||
BINDIR = ../../../../bin
|
||||
INC := $(wildcard *.h) $(wildcard *.inl)
|
||||
INC := $(notdir $(INC))
|
||||
SRC := $(wildcard $(SRCDIR)/*.cpp)
|
||||
SRC := $(notdir $(SRC))
|
||||
OBJDIR := $(CONFIG)
|
||||
OBJ := $(SRC:%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
all : $(EXE)
|
||||
|
||||
$(OBJDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
$(CC) -o $@ $(INCPATH) $(CFLAGS) $<
|
||||
|
||||
clean :
|
||||
rm -f $(OBJDIR)/*.o
|
||||
|
||||
$(EXE) : $(OBJ)
|
||||
$(CC) $(OBJ) -L$(BINDIR) -lhelloLibrary$(SUFFIX) -o $(BINDIR)/$(EXE)$(SUFFIX)
|
||||
|
||||
CC = /usr/bin/g++
|
||||
CFLAGS = -c -Wall -ansi
|
||||
EXE = helloLibrary_Tests
|
||||
SUFFIX = d
|
||||
|
||||
ifeq (debug,$(CONFIG))
|
||||
CFLAGS += -O2 -DNDEBUG
|
||||
SUFFIX = d
|
||||
else
|
||||
CFLAGS += -g -D_DEBUG
|
||||
SUFFIX =
|
||||
endif
|
||||
|
||||
INCPATH = -I../../../../include
|
||||
SRCDIR = ../../../../Applications/Tests/helloLibrary
|
||||
BINDIR = ../../../../bin
|
||||
INC := $(wildcard *.h) $(wildcard *.inl)
|
||||
INC := $(notdir $(INC))
|
||||
SRC := $(wildcard $(SRCDIR)/*.cpp)
|
||||
SRC := $(notdir $(SRC))
|
||||
OBJDIR := $(CONFIG)
|
||||
OBJ := $(SRC:%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
all : $(EXE)
|
||||
|
||||
$(OBJDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
$(CC) -o $@ $(INCPATH) $(CFLAGS) $<
|
||||
|
||||
clean :
|
||||
rm -f $(OBJDIR)/*.o
|
||||
|
||||
$(EXE) : $(OBJ)
|
||||
$(CC) $(OBJ) -L$(BINDIR) -lhelloLibrary$(SUFFIX) -o $(BINDIR)/$(EXE)$(SUFFIX)
|
||||
|
@ -1,7 +1,7 @@
|
||||
build:
|
||||
@mkdir -p $(CONFIG)
|
||||
make -f makeprj.lnx CONFIG=$(CONFIG)
|
||||
|
||||
clean:
|
||||
make clean -f makeprj.lnx CONFIG=debug
|
||||
make clean -f makeprj.lnx CONFIG=release
|
||||
build:
|
||||
@mkdir -p $(CONFIG)
|
||||
make -f makeprj.lnx CONFIG=$(CONFIG)
|
||||
|
||||
clean:
|
||||
make clean -f makeprj.lnx CONFIG=debug
|
||||
make clean -f makeprj.lnx CONFIG=release
|
@ -1,34 +1,34 @@
|
||||
CC = /usr/bin/g++
|
||||
CFLAGS = -c -Wall -ansi
|
||||
DLL = libhelloLibrary
|
||||
SUFFIX = d
|
||||
|
||||
ifeq (debug,$(CONFIG))
|
||||
CFLAGS += -O2 -DNDEBUG
|
||||
SUFFIX = d
|
||||
else
|
||||
CFLAGS += -g -D_DEBUG
|
||||
SUFFIX =
|
||||
endif
|
||||
|
||||
INCPATH = -I../../include
|
||||
SRCDIR = ../../src/helloLibrary
|
||||
BINDIR = ../../bin
|
||||
INC := $(wildcard *.h) $(wildcard *.inl)
|
||||
INC := $(notdir $(INC))
|
||||
SRC := $(wildcard $(SRCDIR)/*.cpp)
|
||||
SRC := $(notdir $(SRC))
|
||||
OBJDIR := $(CONFIG)
|
||||
OBJ := $(SRC:%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
all : $(DLL)
|
||||
|
||||
$(OBJDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
$(CC) -o $@ $(INCPATH) $(CFLAGS) $<
|
||||
|
||||
clean :
|
||||
rm -f $(OBJDIR)/*.o
|
||||
|
||||
$(DLL) : $(OBJ)
|
||||
$(CC) -fdiagnostics-show-option -o $(BINDIR)/$(DLL)$(SUFFIX).so -shared $(OBJDIR)/*.o 2> $(BINDIR)/build.log
|
||||
CC = /usr/bin/g++
|
||||
CFLAGS = -c -Wall -ansi
|
||||
DLL = libhelloLibrary
|
||||
SUFFIX = d
|
||||
|
||||
ifeq (debug,$(CONFIG))
|
||||
CFLAGS += -O2 -DNDEBUG
|
||||
SUFFIX = d
|
||||
else
|
||||
CFLAGS += -g -D_DEBUG
|
||||
SUFFIX =
|
||||
endif
|
||||
|
||||
INCPATH = -I../../include
|
||||
SRCDIR = ../../src/helloLibrary
|
||||
BINDIR = ../../bin
|
||||
INC := $(wildcard *.h) $(wildcard *.inl)
|
||||
INC := $(notdir $(INC))
|
||||
SRC := $(wildcard $(SRCDIR)/*.cpp)
|
||||
SRC := $(notdir $(SRC))
|
||||
OBJDIR := $(CONFIG)
|
||||
OBJ := $(SRC:%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
all : $(DLL)
|
||||
|
||||
$(OBJDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
$(CC) -o $@ $(INCPATH) $(CFLAGS) $<
|
||||
|
||||
clean :
|
||||
rm -f $(OBJDIR)/*.o
|
||||
|
||||
$(DLL) : $(OBJ)
|
||||
$(CC) -fdiagnostics-show-option -o $(BINDIR)/$(DLL)$(SUFFIX).so -shared $(OBJDIR)/*.o 2> $(BINDIR)/build.log
|
||||
# ld -o $(BINDIR)/$(DLL)$(SUFFIX).so -shared $(OBJDIR)/*.o
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
project( visnode )
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
SET("OpenCV_DIR" "/usr/local/lib/")
|
||||
include_directories(${OpenCV_INCLUDE_DIRS} )
|
||||
link_directories(${Opencv_LINK_DIRS})
|
||||
|
||||
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/../bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_subdirectory(threadweaver)
|
||||
add_subdirectory(ihidapi)
|
||||
add_subdirectory(cameras)
|
||||
add_subdirectory(psvr)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(hw)
|
||||
|
||||
set(main_source_files main.cpp main.hpp)
|
||||
|
||||
add_executable(prog ${main_source_files})
|
||||
|
||||
target_link_libraries(prog hw)
|
||||
|
||||
|
||||
SET(GCC_COVERAGE_COMPILE_FLAGS "-L/usr/local/lib")
|
||||
add_definitions(${GCC_COVERAGE_COMPILE_FLAGS})
|
@ -0,0 +1,45 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <execution>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <opencv4/opencv2/opencv.hpp>
|
||||
#include "../threadweaver/threadweaver.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();
|
||||
#define DEBUG_SHOW_ELAPSED uint elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(bge - bgd).count();std::cout << "Time difference = " << elapsed << "[ms] " << (1000/elapsed) <<"[fps]"<< std::endl;
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
std::vector<std::string> listCameras();
|
||||
|
||||
class camera{
|
||||
public:
|
||||
uint path;
|
||||
VideoCapture* source;
|
||||
int Yindex = 0; //index for the stitcher
|
||||
};
|
||||
|
||||
class cameraManager{
|
||||
public:
|
||||
static std::vector<camera*> videoSources;
|
||||
static std::vector<Mat> captures;
|
||||
static std::vector<std::mutex*> accessLocks;
|
||||
static bool runCaptureThread;
|
||||
static int init();
|
||||
static void runCapture();
|
||||
static void stopCapture();
|
||||
static void runCaptureForCamera(camera* c, uint index);
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=$(dpkg -s libhidapi-dev 2> /dev/null | grep "Version" | cut -d':' -f2)
|
||||
|
||||
HEADERS="./threadweaver/*.hpp ./cameras/_cam.hpp ./hidapi/_hidapi.hpp ./psvr/_psvr.hpp ./ui/uiElements/uiElements.hpp ./ui/_ui.hpp ./hw/*.hpp ./main.hpp"
|
||||
SOURCES="./threadweaver/*.cpp ./cameras/*.cpp ./hidapi/*.cpp ./psvr/*.cpp ./ui/uiElements/*.cpp ./ui/*.cpp ./hw/*.cpp ./main.cpp"
|
||||
LIBRARIES="-ltbb -l:libhidapi-hidraw.so.0 -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_videoio -std=c++17"
|
||||
|
||||
INCLUDE_PATHS="-I/usr/local/include/opencv4"
|
||||
# LIBRARY_PATHS="-L/lib/x86_64-linux-gnu/ -L/usr/local/lib/"
|
||||
LIBRARY_PATHS="-L/lib/aarch64-linux-gnu/ -L/usr/local/lib/"
|
||||
|
||||
if [[ -z $VERSION ]]
|
||||
then
|
||||
echo "libhidapi is not installed, installing now"
|
||||
sudo apt install libhidapi-dev
|
||||
elif [[ $VERSION != " 0.11.2-1" ]]
|
||||
then
|
||||
echo "|"$VERSION"|"
|
||||
echo "libhidapi is not the right version, updating now"
|
||||
sudo apt --only-upgrade install libhidapi-dev
|
||||
else
|
||||
echo "libhidapi is installed"
|
||||
fi
|
||||
|
||||
echo "compiling..."
|
||||
g++ -Ofast -pg $SOURCES $HEADERS $INCLUDE_PATHS $LIBRARY_PATHS $LIBRARIES -o prog
|
||||
echo "done compiling"
|
@ -0,0 +1,22 @@
|
||||
// C library headers
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// Linux headers
|
||||
#include <fcntl.h> // Contains file controls like O_RDWR
|
||||
#include <errno.h> // Error integer and strerror() function
|
||||
#include <termios.h> // Contains POSIX terminal control definitions
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "../ui/_ui.hpp"
|
||||
|
||||
class SerialPortManager{
|
||||
public:
|
||||
static void init();
|
||||
static void runPort();
|
||||
static bool shouldRun;
|
||||
static int serialPort;
|
||||
};
|
@ -0,0 +1,6 @@
|
||||
#include <hidapi/hidapi.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace hid_func{
|
||||
hid_device* open_device_idx(int manufacturer, int product, int iface, int device_index);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#include "main.hpp"
|
||||
#include <future>
|
||||
using namespace psvr;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//psvr::Psvr::open();
|
||||
ui::UiManager::init();
|
||||
std::future<int> fobj = std::async (cameraManager::init); //asynchronous camera manager start
|
||||
ui::UiController::init();
|
||||
std::future<void> menudraw = std::async (ui::UiDrawer::drawMenu);
|
||||
ui::UiDrawer::drawStartupSequence(); //show startup sequence while camera manager is starting
|
||||
menudraw.get();
|
||||
fobj.get();
|
||||
cameraManager::runCapture();
|
||||
SerialPortManager::init();
|
||||
ui::UiController::exitCalled = false;
|
||||
while(!ui::UiController::exitCalled){
|
||||
std::future<void> uiL = std::async (ui::UiDrawer::drawUiL);
|
||||
std::future<void> uiR = std::async (ui::UiDrawer::drawUiR);
|
||||
uiL.get();
|
||||
uiR.get();
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "./hw/serial.hpp"
|
@ -0,0 +1,29 @@
|
||||
#include "../ihidapi/_hidapi.hpp"
|
||||
|
||||
const unsigned char psvr_vrmode_off[8] {0x23,0x00,0xaa,0x04,0x00,0x00,0x00,0x00};
|
||||
const unsigned char psvr_vrmode_on[8] {0x23,0x00,0xaa,0x04,0x01,0x00,0x00,0x00};
|
||||
const unsigned char psvr_power_off[8] {0x17,0x00,0xaa,0x04,0x01,0x00,0x00,0x00};
|
||||
const unsigned char psvr_power_on[8] {0x17,0x00,0xaa,0x04,0x00,0x00,0x00,0x00};
|
||||
|
||||
#define sony_vid 0x054c
|
||||
#define psvr_pid 0x09af
|
||||
#define ctrl_device_iface 5
|
||||
#define ld_device_iface 4
|
||||
|
||||
namespace psvr{
|
||||
class Psvr{
|
||||
public:
|
||||
static hid_device* handle;
|
||||
static bool vrMode;
|
||||
static bool powered;
|
||||
|
||||
static void open(); //default constructor
|
||||
|
||||
static void startup();
|
||||
static void shutdown();
|
||||
static void vrmode();
|
||||
static void cinemaMode();
|
||||
|
||||
static void close();//default destructor
|
||||
};
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
//main thread manager
|
||||
class Threadweaver{
|
||||
public:
|
||||
static std::vector<std::thread*> captureThreads;
|
||||
static std::thread* hardwareWatcherThread;
|
||||
static std::thread* osUiDrawerThread;
|
||||
};
|
@ -0,0 +1,72 @@
|
||||
#include<iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
|
||||
#include "../cameras/_cam.hpp"
|
||||
#include "../psvr/_psvr.hpp"
|
||||
#include <opencv4/opencv2/imgcodecs/imgcodecs.hpp>
|
||||
|
||||
#define DEFAULT_UI_WINDOW_AMOUNT 2 //2 windows, one for each eye
|
||||
#define DEFAULT_UI_OFFSET_X 0 //1080
|
||||
#define DEFAULT_UI_OFFSET_Y 0
|
||||
#define DEFAULT_UI_SIZE_X 960 //psvr is 960x1080 per eye
|
||||
#define DEFAULT_UI_SIZE_Y 1080
|
||||
|
||||
int runtest();
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace psvr;
|
||||
|
||||
namespace ui {
|
||||
//Defines a single ui window (by default two will be displayed)
|
||||
class Ui{
|
||||
public:
|
||||
Mat drawSurface; //Current frame
|
||||
std::string myWindow;
|
||||
void draw();
|
||||
};
|
||||
class UiDrawer{ //drawer is static because we only ever need one
|
||||
public:
|
||||
static void drawUiR();
|
||||
static void drawUiL();
|
||||
static void drawStartupSequence();
|
||||
static void drawMenu();
|
||||
static Mat OverlayMat; //drawn at each frame
|
||||
static Mat OsMat; //drawn on certain events
|
||||
static std::mutex OsMatLock;
|
||||
private:
|
||||
static Mat prepareUiMat();
|
||||
static Mat resizeIn(Mat input);
|
||||
static Mat OverlayBlackMask(Mat input, Mat toOverlay, int x = 0, int y = 0);
|
||||
static Mat OverlayHISHMask(Mat input, Mat toOverlay);
|
||||
};
|
||||
class UiManager{ //manager is static because we only ever need one
|
||||
public:
|
||||
static vector<Ui*> managedUIs;
|
||||
static void init();
|
||||
static void cleanup();
|
||||
};
|
||||
class UiController{
|
||||
public:
|
||||
static void init();
|
||||
static void selectedUp();
|
||||
static void selectedDown();
|
||||
static void click();
|
||||
static void update();
|
||||
static void openSettings();
|
||||
static vector<std::string> menuItemNames;
|
||||
static bool showMenu;
|
||||
static bool exitCalled;
|
||||
static string menuTitle;
|
||||
static cv::Size2i menuSize;
|
||||
static cv::Point2i menuPos;
|
||||
static unsigned int selectedIndex;
|
||||
static map<std::string, std::function<void()>> menuItems;
|
||||
static char* menutime;
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
#include <opencv4/opencv2/opencv.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
//base UI element class (abstract)
|
||||
struct UiElement{
|
||||
unsigned int xPosPixels;
|
||||
unsigned int yPosPixels;
|
||||
void drawSelf(Mat &input);
|
||||
};
|
||||
//sized ui element (abstract)
|
||||
struct SizedUiElement : UiElement{
|
||||
unsigned int widthPixels;
|
||||
unsigned int heightPixels;
|
||||
void drawSelf(Mat &input);
|
||||
};
|
||||
|
||||
struct UiRect : SizedUiElement{
|
||||
unsigned int borderColor;
|
||||
unsigned int fillingColor;
|
||||
void drawSelf(Mat &input);
|
||||
};
|
||||
|
||||
struct UiText : UiElement{
|
||||
std::string text;
|
||||
unsigned int fontSize;
|
||||
cv::Scalar textColor;
|
||||
cv::HersheyFonts font = HersheyFonts::FONT_HERSHEY_SIMPLEX;
|
||||
unsigned int thickness;
|
||||
unsigned int lineType = 0;
|
||||
bool leftOrigin = false;
|
||||
void drawSelf(cv::Mat &input){
|
||||
putText(input, UiText::text, Point(xPosPixels,yPosPixels), cv::FONT_HERSHEY_DUPLEX, fontSize, textColor, thickness, lineType, leftOrigin);
|
||||
}
|
||||
};
|
||||
//menu item container
|
||||
struct UiMenuItem{
|
||||
std::vector<UiElement> elements;
|
||||
};
|
@ -1,31 +0,0 @@
|
||||
#ifndef HL_CLASS1_POINTER_H
|
||||
#define HL_CLASS1_POINTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
///a simple namespace
|
||||
/** a full description
|
||||
*/
|
||||
namespace helloLibrary
|
||||
{
|
||||
///a simple class
|
||||
class Class1
|
||||
{
|
||||
public:
|
||||
///initializes the Class1 instance
|
||||
/** @param text a simple text
|
||||
*/
|
||||
Class1(string text);
|
||||
|
||||
string GetText();
|
||||
|
||||
private:
|
||||
///a simple text
|
||||
string _text;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif //HL_CLASS1_POINTER_H
|
@ -0,0 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
project( visnode )
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
SET("OpenCV_DIR" "/usr/local/lib/")
|
||||
include_directories(${OpenCV_INCLUDE_DIRS} )
|
||||
link_directories(${Opencv_LINK_DIRS})
|
||||
|
||||
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/../bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_subdirectory(threadweaver)
|
||||
add_subdirectory(ihidapi)
|
||||
add_subdirectory(cameras)
|
||||
add_subdirectory(psvr)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(hw)
|
||||
|
||||
set(main_source_files main.cpp main.hpp)
|
||||
|
||||
add_executable(prog ${main_source_files})
|
||||
|
||||
target_link_libraries(prog hw)
|
||||
|
||||
|
||||
SET(GCC_COVERAGE_COMPILE_FLAGS "-L/usr/local/lib")
|
||||
add_definitions(${GCC_COVERAGE_COMPILE_FLAGS})
|
@ -0,0 +1,17 @@
|
||||
set(cameras_source_files
|
||||
camEnum.cpp
|
||||
cameraManager.cpp
|
||||
_cam.hpp
|
||||
)
|
||||
MESSAGE(STATUS "building cameras")
|
||||
add_library(cameras ${cameras_source_files})
|
||||
|
||||
SET("OpenCV_DIR" "/usr/local/lib/")
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
|
||||
MESSAGE(STATUS "Include dirs ${OpenCV_INCLUDE_DIRS}")
|
||||
MESSAGE(STATUS "LINK LIBRARIES ${OpenCV_LIBS}")
|
||||
|
||||
target_link_libraries(cameras OpenCV)
|
||||
MESSAGE(STATUS "Done building cameras")
|
@ -0,0 +1,45 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <execution>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <opencv4/opencv2/opencv.hpp>
|
||||
#include "../threadweaver/threadweaver.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();
|
||||
#define DEBUG_SHOW_ELAPSED uint elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(bge - bgd).count();std::cout << "Time difference = " << elapsed << "[ms] " << (1000/elapsed) <<"[fps]"<< std::endl;
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
std::vector<std::string> listCameras();
|
||||
|
||||
class camera{
|
||||
public:
|
||||
uint path;
|
||||
VideoCapture* source;
|
||||
int Yindex = 0; //index for the stitcher
|
||||
};
|
||||
|
||||
class cameraManager{
|
||||
public:
|
||||
static std::vector<camera*> videoSources;
|
||||
static std::vector<Mat> captures;
|
||||
static std::vector<std::mutex*> accessLocks;
|
||||
static bool runCaptureThread;
|
||||
static int init();
|
||||
static void runCapture();
|
||||
static void stopCapture();
|
||||
static void runCaptureForCamera(camera* c, uint index);
|
||||
};
|
@ -0,0 +1,38 @@
|
||||
#include "_cam.hpp"
|
||||
|
||||
//hidden to the rest of the program
|
||||
std::string exec(const char* cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe) {
|
||||
throw std::runtime_error("popen() failed!");
|
||||
}
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//enumerates the cameras in the system, sends back the camera number for opencv
|
||||
std::vector<std::string> listCameras(){
|
||||
std::cout << "listing cameras" << std::endl;
|
||||
std::vector<std::string> toreturn;
|
||||
std::string to,result = exec("ls /dev/video*");
|
||||
std::cout << "executed list command " << std::endl;
|
||||
|
||||
std::stringstream ss(result);
|
||||
std::cout << "created stringstream" << std::endl;
|
||||
if (result != "")
|
||||
{
|
||||
while(std::getline(ss,to,'\n')){
|
||||
std::cout << "testing interface : " << to << endl;
|
||||
to = std::regex_replace(to, std::regex(R"([\D])"), "");
|
||||
//if(to != "0" && to != "1" && to != "2" && to != "3" && to != "4"){
|
||||
std::cout << "found valid camera " << to << std::endl;
|
||||
toreturn.push_back(to);
|
||||
//}
|
||||
}
|
||||
}
|
||||
return toreturn;
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
#include "_cam.hpp"
|
||||
|
||||
vector<camera*> cameraManager::videoSources;
|
||||
std::vector<Mat> cameraManager::captures;
|
||||
bool cameraManager::runCaptureThread;
|
||||
std::vector<std::mutex*> cameraManager::accessLocks;
|
||||
|
||||
void cameraManager::runCaptureForCamera(camera* c, uint index){
|
||||
while(runCaptureThread){
|
||||
if(!c->source->isOpened()){
|
||||
cout << "camera " << c->path << " is closed, opening..." << endl;
|
||||
if(!c->source->open(c->path,cv::CAP_ANY)){
|
||||
cout << "couldn't open camera with index " << c->path << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if(c->source->grab()){
|
||||
Mat surface;
|
||||
c->source->retrieve(surface);
|
||||
cameraManager::accessLocks[index]->lock();
|
||||
cameraManager::captures[index] = surface;
|
||||
cameraManager::accessLocks[index]->unlock();
|
||||
} else {
|
||||
cout << "read error grabbing from camera " << c->path << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int cameraManager::init(){
|
||||
std::cout << "init camera manager" << endl;
|
||||
vector<std::string> cameras = listCameras();
|
||||
uint cameraIndex = 0;
|
||||
std::cout << "found " << cameras.size() << " cameras" << endl;
|
||||
|
||||
for(string camIdx : cameras) //camera input testing
|
||||
{
|
||||
int camID = stoi(camIdx);
|
||||
try{
|
||||
VideoCapture vs(camID);
|
||||
if(!vs.isOpened() && !vs.open(camID))
|
||||
{
|
||||
cout << "opening camera " << camIdx << " failed" <<endl;
|
||||
}
|
||||
vs.release();
|
||||
camera* cam = new camera();
|
||||
cam->source = new VideoCapture(camID);
|
||||
cam->path = camID;
|
||||
videoSources.push_back(cam); //valid camera added
|
||||
cout << "added camera with path /dev/video" << cam->path << endl;
|
||||
Mat m;
|
||||
captures.push_back(std::move(m));
|
||||
}
|
||||
catch(exception e){
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "found " << std::to_string(videoSources.size()) << " valid cameras" << endl;
|
||||
return videoSources.size();
|
||||
}
|
||||
|
||||
void cameraManager::runCapture(){
|
||||
cout << "enabling capture thread for " << videoSources.size() << " cameras" << endl;
|
||||
uint i = 0;
|
||||
runCaptureThread = true;
|
||||
for(camera* c : videoSources){
|
||||
mutex* mlock = new mutex();
|
||||
mlock->unlock();
|
||||
accessLocks.push_back(mlock);
|
||||
cout << "enabling camera " << i << endl;
|
||||
std::thread* t = new std::thread(cameraManager::runCaptureForCamera,c,i);
|
||||
i++;
|
||||
cout << "moving thread" << endl;
|
||||
Threadweaver::captureThreads.push_back(t);
|
||||
cout << "done" << endl;
|
||||
}
|
||||
cout << "done enabling threads" << endl;
|
||||
}
|
||||
|
||||
void cameraManager::stopCapture(){
|
||||
runCaptureThread = false;
|
||||
for(std::thread* t : Threadweaver::captureThreads){
|
||||
t->join();
|
||||
delete t;
|
||||
}
|
||||
Threadweaver::captureThreads.clear();
|
||||
for(std::mutex* mlock : accessLocks){
|
||||
mlock->unlock();
|
||||
delete mlock;
|
||||
}
|
||||
accessLocks.clear();
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=$(dpkg -s libhidapi-dev 2> /dev/null | grep "Version" | cut -d':' -f2)
|
||||
|
||||
HEADERS="./threadweaver/*.hpp ./cameras/_cam.hpp ./hidapi/_hidapi.hpp ./psvr/_psvr.hpp ./ui/uiElements/uiElements.hpp ./ui/_ui.hpp ./hw/*.hpp ./main.hpp"
|
||||
SOURCES="./threadweaver/*.cpp ./cameras/*.cpp ./hidapi/*.cpp ./psvr/*.cpp ./ui/uiElements/*.cpp ./ui/*.cpp ./hw/*.cpp ./main.cpp"
|
||||
LIBRARIES="-ltbb -l:libhidapi-hidraw.so.0 -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_videoio -std=c++17"
|
||||
|
||||
INCLUDE_PATHS="-I/usr/local/include/opencv4"
|
||||
# LIBRARY_PATHS="-L/lib/x86_64-linux-gnu/ -L/usr/local/lib/"
|
||||
LIBRARY_PATHS="-L/lib/aarch64-linux-gnu/ -L/usr/local/lib/"
|
||||
|
||||
if [[ -z $VERSION ]]
|
||||
then
|
||||
echo "libhidapi is not installed, installing now"
|
||||
sudo apt install libhidapi-dev
|
||||
elif [[ $VERSION != " 0.11.2-1" ]]
|
||||
then
|
||||
echo "|"$VERSION"|"
|
||||
echo "libhidapi is not the right version, updating now"
|
||||
sudo apt --only-upgrade install libhidapi-dev
|
||||
else
|
||||
echo "libhidapi is installed"
|
||||
fi
|
||||
|
||||
echo "compiling..."
|
||||
g++ -Ofast -pg $SOURCES $HEADERS $INCLUDE_PATHS $LIBRARY_PATHS $LIBRARIES -o prog
|
||||
echo "done compiling"
|
@ -0,0 +1,9 @@
|
||||
set(hw_source_files
|
||||
serial.cpp
|
||||
serial.hpp
|
||||
)
|
||||
MESSAGE(STATUS "building hw")
|
||||
add_library(hw ${hw_source_files})
|
||||
|
||||
target_link_libraries(hw ui)
|
||||
MESSAGE(STATUS "Done building hw")
|
@ -0,0 +1,88 @@
|
||||
#include "./serial.hpp"
|
||||
|
||||
bool SerialPortManager::shouldRun;
|
||||
int SerialPortManager::serialPort;
|
||||
|
||||
void SerialPortManager::init(){
|
||||
struct termios tty;
|
||||
|
||||
cout << "opening serial port /dev/ttyUSB0" << endl;
|
||||
serialPort = open("/dev/ttyUSB0", O_RDWR); //open serial port
|
||||
cout << "done" << endl;
|
||||
|
||||
if (serialPort < 0){
|
||||
printf("Error %i from open: %s\n", errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if(tcgetattr(serialPort, &tty) != 0){ //read serial port configuration
|
||||
printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
//local flags
|
||||
tty.c_lflag &= ~ICANON; //enable canonical mode
|
||||
tty.c_lflag &= ~ECHO; // Disable echo
|
||||
tty.c_lflag &= ~ECHOE; // Disable erasure
|
||||
tty.c_lflag &= ~ECHONL; // Disable new-line echo
|
||||
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
|
||||
//input modes
|
||||
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
|
||||
tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes
|
||||
//output modes
|
||||
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
||||
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
||||
//c_cc
|
||||
tty.c_cc[VTIME] = 1; // Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
|
||||
tty.c_cc[VMIN] = 0;
|
||||
//baudrate
|
||||
cfsetispeed(&tty, B9600); //set baudrate (input)
|
||||
cfsetospeed(&tty, B9600); // (output)
|
||||
|
||||
// Save tty settings, also checking for error
|
||||
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
||||
printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
shouldRun = true;
|
||||
cout << "starting hardware watcher thread" << endl;
|
||||
std::thread* t = new std::thread(SerialPortManager::runPort);
|
||||
cout << "done" << endl;
|
||||
Threadweaver::hardwareWatcherThread = t;
|
||||
}
|
||||
|
||||
void SerialPortManager::runPort(){
|
||||
char read_buf [256];
|
||||
int n = 0;
|
||||
while(shouldRun){
|
||||
n = read(serialPort, &read_buf, sizeof(read_buf));
|
||||
if(n > 0){
|
||||
char c = read_buf[0];
|
||||
switch(c){
|
||||
case 'U':
|
||||
cout << c << "++" << endl;
|
||||
ui::UiController::selectedUp();
|
||||
break;
|
||||
case 'D':
|
||||
cout << c << "--" << endl;
|
||||
ui::UiController::selectedDown();
|
||||
break;
|
||||
case '1':
|
||||
ui::UiController::click();
|
||||
break;
|
||||
case '2':
|
||||
ui::UiController::click();
|
||||
break;
|
||||
case '3':
|
||||
ui::UiController::click();
|
||||
break;
|
||||
case '4':
|
||||
ui::UiController::click();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::fill_n(read_buf, n, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// C library headers
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// Linux headers
|
||||
#include <fcntl.h> // Contains file controls like O_RDWR
|
||||
#include <errno.h> // Error integer and strerror() function
|
||||
#include <termios.h> // Contains POSIX terminal control definitions
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "../ui/_ui.hpp"
|
||||
|
||||
class SerialPortManager{
|
||||
public:
|
||||
static void init();
|
||||
static void runPort();
|
||||
static bool shouldRun;
|
||||
static int serialPort;
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
set(ihidapi_source_files
|
||||
hidapi_functions.cpp
|
||||
_hidapi.hpp
|
||||
)
|
||||
MESSAGE(STATUS "Building ihidapi")
|
||||
add_library(ihiadpi ${ihidapi_source_files})
|
||||
|
||||
find_package(hidapi REQUIRED)
|
||||
|
||||
target_link_libraries(ihiadpi hidapi::hidapi)
|
||||
|
||||
MESSAGE(STATUS "Done building ihidapi")
|
@ -0,0 +1,6 @@
|
||||
#include <hidapi/hidapi.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace hid_func{
|
||||
hid_device* open_device_idx(int manufacturer, int product, int iface, int device_index);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#include "_hidapi.hpp"
|
||||
|
||||
namespace hid_func{
|
||||
|
||||
hid_device* open_device_idx(int manufacturer, int product, int iface, int device_index)
|
||||
{
|
||||
struct hid_device_info* devs = hid_enumerate(manufacturer, product);
|
||||
struct hid_device_info* cur_dev = devs;
|
||||
|
||||
int idx = 0;
|
||||
hid_device* ret = NULL;
|
||||
|
||||
while (cur_dev) {
|
||||
std::cout << manufacturer << product << cur_dev->path << std::endl;
|
||||
|
||||
if (cur_dev->interface_number == iface) {
|
||||
if (idx == device_index) {
|
||||
std::cout << "\topening " << cur_dev->path << std::endl;
|
||||
ret = hid_open_path(cur_dev->path);
|
||||
break;
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
cur_dev = cur_dev->next;
|
||||
}
|
||||
|
||||
hid_free_enumeration(devs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#include "main.hpp"
|
||||
#include <future>
|
||||
using namespace psvr;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//psvr::Psvr::open();
|
||||
ui::UiManager::init();
|
||||
std::future<int> fobj = std::async (cameraManager::init); //asynchronous camera manager start
|
||||
ui::UiController::init();
|
||||
std::future<void> menudraw = std::async (ui::UiDrawer::drawMenu);
|
||||
ui::UiDrawer::drawStartupSequence(); //show startup sequence while camera manager is starting
|
||||
menudraw.get();
|
||||
fobj.get();
|
||||
cameraManager::runCapture();
|
||||
SerialPortManager::init();
|
||||
ui::UiController::exitCalled = false;
|
||||
while(!ui::UiController::exitCalled){
|
||||
std::future<void> uiL = std::async (ui::UiDrawer::drawUiL);
|
||||
std::future<void> uiR = std::async (ui::UiDrawer::drawUiR);
|
||||
uiL.get();
|
||||
uiR.get();
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "./hw/serial.hpp"
|
After Width: | Height: | Size: 572 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 218 KiB |
@ -0,0 +1,10 @@
|
||||
set(psvr_source_files
|
||||
psvr.cpp
|
||||
_psvr.hpp
|
||||
)
|
||||
MESSAGE(STATUS "building psvr")
|
||||
add_library(psvr ${psvr_source_files})
|
||||
|
||||
target_link_libraries(cameras ihidapi)
|
||||
|
||||
MESSAGE(STATUS "Done building psvr")
|
@ -0,0 +1,29 @@
|
||||
#include "../ihidapi/_hidapi.hpp"
|
||||
|
||||
const unsigned char psvr_vrmode_off[8] {0x23,0x00,0xaa,0x04,0x00,0x00,0x00,0x00};
|
||||
const unsigned char psvr_vrmode_on[8] {0x23,0x00,0xaa,0x04,0x01,0x00,0x00,0x00};
|
||||
const unsigned char psvr_power_off[8] {0x17,0x00,0xaa,0x04,0x01,0x00,0x00,0x00};
|
||||
const unsigned char psvr_power_on[8] {0x17,0x00,0xaa,0x04,0x00,0x00,0x00,0x00};
|
||||
|
||||
#define sony_vid 0x054c
|
||||
#define psvr_pid 0x09af
|
||||
#define ctrl_device_iface 5
|
||||
#define ld_device_iface 4
|
||||
|
||||
namespace psvr{
|
||||
class Psvr{
|
||||
public:
|
||||
static hid_device* handle;
|
||||
static bool vrMode;
|
||||
static bool powered;
|
||||
|
||||
static void open(); //default constructor
|
||||
|
||||
static void startup();
|
||||
static void shutdown();
|
||||
static void vrmode();
|
||||
static void cinemaMode();
|
||||
|
||||
static void close();//default destructor
|
||||
};
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
#include "_psvr.hpp"
|
||||
|
||||
namespace psvr{
|
||||
hid_device* Psvr::handle;
|
||||
bool Psvr::vrMode;
|
||||
bool Psvr::powered;
|
||||
|
||||
void Psvr::open(){
|
||||
int res = hid_init();
|
||||
handle = hid_func::open_device_idx(sony_vid, psvr_pid, ctrl_device_iface, 0);
|
||||
|
||||
if (!handle) {
|
||||
std::cout << "failed to open PSVR control handle" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (hid_set_nonblocking(handle, 1) == -1) {
|
||||
std::cout << "failed to set non-blocking on device" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
startup();
|
||||
}
|
||||
|
||||
void Psvr::startup(){
|
||||
//no check because power on is critical
|
||||
if (hid_write(handle, psvr_power_on, sizeof(psvr_power_on)) == -1) {
|
||||
std::cout << "failed to write to device (power on)" << std::endl;
|
||||
return;
|
||||
}
|
||||
powered = true;
|
||||
}
|
||||
|
||||
void Psvr::shutdown(){
|
||||
if(!powered) return;
|
||||
if (hid_write(handle, psvr_power_off, sizeof(psvr_power_off)) == -1) {
|
||||
std::cout << "failed to write to device (power off)" << std::endl;
|
||||
return;
|
||||
}
|
||||
powered = false;
|
||||
}
|
||||
|
||||
void Psvr::vrmode(){
|
||||
if(vrMode) return;
|
||||
if (hid_write(handle, psvr_vrmode_on, sizeof(psvr_vrmode_on)) == -1) {
|
||||
std::cout << "failed to write to device (set VR mode)" << std::endl;
|
||||
return;
|
||||
}
|
||||
vrMode = true;
|
||||
}
|
||||
|
||||
void Psvr::cinemaMode(){
|
||||
if(!vrMode) return;
|
||||
if (hid_write(handle, psvr_vrmode_off, sizeof(psvr_vrmode_off)) == -1) {
|
||||
std::cout << "failed to write to device (set VR mode off)" << std::endl;
|
||||
return;
|
||||
}
|
||||
vrMode = false;
|
||||
}
|
||||
|
||||
void Psvr::close(){
|
||||
if(powered) shutdown();
|
||||
hid_close(handle);
|
||||
int res = hid_exit();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
set(thredweaver_source_files
|
||||
threadweaver.cpp
|
||||
threadweaver.hpp
|
||||
)
|
||||
MESSAGE(STATUS "building threadweaver")
|
||||
add_library(threadweaver ${thredweaver_source_files})
|
||||
MESSAGE(STATUS "done building threadweaver")
|
@ -0,0 +1,5 @@
|
||||
#include "./threadweaver.hpp"
|
||||
|
||||
std::vector<std::thread*> Threadweaver::captureThreads;
|
||||
std::thread* Threadweaver::hardwareWatcherThread;
|
||||
std::thread* Threadweaver::osUiDrawerThread;
|
@ -0,0 +1,10 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
//main thread manager
|
||||
class Threadweaver{
|
||||
public:
|
||||
static std::vector<std::thread*> captureThreads;
|
||||
static std::thread* hardwareWatcherThread;
|
||||
static std::thread* osUiDrawerThread;
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
set(ui_source_files
|
||||
./uiElements/uiElements.cpp
|
||||
./uiElements/uiElements.hpp
|
||||
ui.cpp
|
||||
uiController.cpp
|
||||
uiDrawer.cpp
|
||||
uiManager.cpp
|
||||
_ui.hpp
|
||||
)
|
||||
MESSAGE(STATUS "building ui")
|
||||
SET("OpenCV_DIR" "/usr/local/lib/")
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
|
||||
|
||||
add_library(ui ${ui_source_files})
|
||||
|
||||
target_link_libraries(ui Opencv)
|
||||
MESSAGE(STATUS "Done building ui")
|
@ -0,0 +1,72 @@
|
||||
#include<iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
|
||||
#include "../cameras/_cam.hpp"
|
||||
#include "../psvr/_psvr.hpp"
|
||||
#include <opencv4/opencv2/imgcodecs/imgcodecs.hpp>
|
||||
|
||||
#define DEFAULT_UI_WINDOW_AMOUNT 2 //2 windows, one for each eye
|
||||
#define DEFAULT_UI_OFFSET_X 0 //1080
|
||||
#define DEFAULT_UI_OFFSET_Y 0
|
||||
#define DEFAULT_UI_SIZE_X 960 //psvr is 960x1080 per eye
|
||||
#define DEFAULT_UI_SIZE_Y 1080
|
||||
|
||||
int runtest();
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace psvr;
|
||||
|
||||
namespace ui {
|
||||
//Defines a single ui window (by default two will be displayed)
|
||||
class Ui{
|
||||
public:
|
||||
Mat drawSurface; //Current frame
|
||||
std::string myWindow;
|
||||
void draw();
|
||||
};
|
||||
class UiDrawer{ //drawer is static because we only ever need one
|
||||
public:
|
||||
static void drawUiR();
|
||||
static void drawUiL();
|
||||
static void drawStartupSequence();
|
||||
static void drawMenu();
|
||||
static Mat OverlayMat; //drawn at each frame
|
||||
static Mat OsMat; //drawn on certain events
|
||||
static std::mutex OsMatLock;
|
||||
private:
|
||||
static Mat prepareUiMat();
|
||||
static Mat resizeIn(Mat input);
|
||||
static Mat OverlayBlackMask(Mat input, Mat toOverlay, int x = 0, int y = 0);
|
||||
static Mat OverlayHISHMask(Mat input, Mat toOverlay);
|
||||
};
|
||||
class UiManager{ //manager is static because we only ever need one
|
||||
public:
|
||||
static vector<Ui*> managedUIs;
|
||||
static void init();
|
||||
static void cleanup();
|
||||
};
|
||||
class UiController{
|
||||
public:
|
||||
static void init();
|
||||
static void selectedUp();
|
||||
static void selectedDown();
|
||||
static void click();
|
||||
static void update();
|
||||
static void openSettings();
|
||||
static vector<std::string> menuItemNames;
|
||||
static bool showMenu;
|
||||
static bool exitCalled;
|
||||
static string menuTitle;
|
||||
static cv::Size2i menuSize;
|
||||
static cv::Point2i menuPos;
|
||||
static unsigned int selectedIndex;
|
||||
static map<std::string, std::function<void()>> menuItems;
|
||||
static char* menutime;
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
#include "_ui.hpp"
|
||||
|
||||
void ui::Ui::draw(){
|
||||
if(drawSurface.empty())
|
||||
return;
|
||||
imshow(this->myWindow, this->drawSurface);
|
||||
waitKey(1);
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
#include "_ui.hpp"
|
||||
|
||||
bool ui::UiController::showMenu;
|
||||
bool ui::UiController::exitCalled;
|
||||
cv::Size2i ui::UiController::menuSize;
|
||||
cv::Point2i ui::UiController::menuPos;
|
||||
unsigned int ui::UiController::selectedIndex;
|
||||
map<std::string, std::function<void()>> ui::UiController::menuItems;
|
||||
string ui::UiController::menuTitle;
|
||||
char* ui::UiController::menutime;
|
||||
vector<std::string> ui::UiController::menuItemNames = {"set vr mode","set cinema mode","settings"};
|
||||
|
||||
void ui::UiController::init(){
|
||||
std::cout << "init ui controller" << endl;
|
||||
showMenu = true;
|
||||
menuSize = cv::Size2i(400,400);
|
||||
menuPos = cv::Point2i(DEFAULT_UI_SIZE_X-menuSize.width,(DEFAULT_UI_SIZE_Y/2)-(menuSize.height/2)); //centered right
|
||||
selectedIndex = 0;
|
||||
menuItemNames = {"set vr mode","set cinema mode","settings"};
|
||||
vector<std::function<void()>> functions = {psvr::Psvr::vrmode, psvr::Psvr::cinemaMode, UiController::openSettings};
|
||||
unsigned int i = 0;
|
||||
for(std::string name : menuItemNames){
|
||||
menuItems[name] = functions.at(i);
|
||||
i++;
|
||||
}
|
||||
update();
|
||||
cout << "done init ui controller" << endl;
|
||||
}
|
||||
|
||||
void ui::UiController::update(){
|
||||
time_t now = time(0);
|
||||
menutime = ctime(&now);
|
||||
menuTitle = std::string("P-OS V0.1 ") + menutime;
|
||||
}
|
||||
|
||||
void ui::UiController::selectedUp(){
|
||||
if(selectedIndex < menuItems.size()-1) selectedIndex++;
|
||||
}
|
||||
|
||||
void ui::UiController::selectedDown(){
|
||||
if(selectedIndex > 0) selectedIndex--;
|
||||
}
|
||||
|
||||
void ui::UiController::openSettings(){
|
||||
|
||||
}
|
||||
|
||||
void ui::UiController::click(){
|
||||
ui::UiController::exitCalled = true;
|
||||
//std::invoke(menuItems[menuItemNames.at(selectedIndex)]);
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
#include "_ui.hpp"
|
||||
Mat ui::UiDrawer::OverlayMat;
|
||||
Mat ui::UiDrawer::OsMat; //drawn on certain events
|
||||
std::mutex ui::UiDrawer::OsMatLock;
|
||||
|
||||
//UiMat = prepareUiMat();
|
||||
//surface.copyTo(UiMat(cv::Rect((UiMat.cols/2)-(surface.cols/2),(UiMat.rows/2)-(surface.rows/2),surface.cols, surface.rows)));
|
||||
//UiMat = OverlayBlackMask(UiMat, overlay);
|
||||
|
||||
namespace ui{
|
||||
//draws the UI for the left screen of the psvr
|
||||
void UiDrawer::drawUiL(){
|
||||
Mat UiMat = prepareUiMat(); //prepare black background
|
||||
cameraManager::accessLocks[0]->lock(); //lock the capture access
|
||||
Mat surface = 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
|
||||
//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)));
|
||||
UiMat = OverlayBlackMask(UiMat, OverlayMat); //add the fixed overlay
|
||||
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[0]->drawSurface = UiMat; //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(){
|
||||
VideoCapture cap("./media/hud_startup.gif");
|
||||
Mat overlay = imread("./media/hud_fixed.png",-1);
|
||||
cout << "read overlay" << endl;
|
||||
ui::UiDrawer::OverlayMat = overlay;
|
||||
if(!cap.isOpened()){
|
||||
cout << "failed to open hud start media" << endl;
|
||||
//return;
|
||||
}
|
||||
Mat frame;
|
||||
for(;;)
|
||||
{
|
||||
if(!cap.read(frame)) break;
|
||||
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();
|
||||
}
|
||||
|
||||
void UiDrawer::drawMenu(){
|
||||
int& wd = UiController::menuSize.width;
|
||||
int& he = UiController::menuSize.height;
|
||||
unsigned int stackerIndex = 0;
|
||||
Mat MenuMat(cv::Size(wd, he), CV_8UC3,Scalar(0,0,0));
|
||||
cv::rectangle(MenuMat, cv::Rect2i(0,0,wd, he), Scalar(255,0,0), 5, 8, 0);
|
||||
ui::UiController::update();
|
||||
cv::putText(MenuMat, UiController::menuTitle, Point2i(5,stackerIndex+=20), HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255,255,255), 1, 8, false);
|
||||
for(std::map<std::string,std::function<void()>>::iterator iter = UiController::menuItems.begin(); iter != UiController::menuItems.end(); ++iter)
|
||||
{
|
||||
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::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();
|
||||
}
|
||||
|
||||
Mat UiDrawer::prepareUiMat(){
|
||||
Mat blk960x1080(cv::Size(960, 1080), CV_8UC3,Scalar(0,0,0));
|
||||
return blk960x1080;
|
||||
}
|
||||
|
||||
Mat UiDrawer::resizeIn(Mat input){
|
||||
Mat output;
|
||||
resize(input, output, Size(960, 1080), InterpolationFlags::INTER_LINEAR);
|
||||
return output;
|
||||
}
|
||||
|
||||
///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){
|
||||
if(input.cols < toOverlay.cols || input.rows < toOverlay.rows) return input;
|
||||
|
||||
Mat toOverlayGRAY, mask;
|
||||
vector<Mat> Bands;
|
||||
|
||||
if(toOverlay.channels() == 3){ //non transparent image, use black as mask
|
||||
cvtColor(toOverlay,toOverlayGRAY, COLOR_BGR2GRAY); //picture to greyscale
|
||||
threshold(toOverlayGRAY, mask, 0, 255, THRESH_BINARY); //greyscale to alpha (black or not)
|
||||
} else if (toOverlay.channels() == 4){ //transparent, use alpha layer as mask
|
||||
split(toOverlay,Bands); // seperate channels
|
||||
Mat channels[3] = { Bands[0],Bands[1],Bands[2] };
|
||||
merge(channels,3,toOverlay); // glue together again
|
||||
mask = Bands[3]; // png's alpha channel used as mask
|
||||
}
|
||||
toOverlay.copyTo(input(cv::Rect(x,y,toOverlay.cols, toOverlay.rows)),mask);
|
||||
return input;
|
||||
}
|
||||
|
||||
Mat UiDrawer::OverlayHISHMask(Mat input, Mat toOverlay){
|
||||
if(input.cols < toOverlay.cols || input.rows < toOverlay.rows) return input;
|
||||
|
||||
Mat toOverlayGRAY, mask;
|
||||
vector<Mat> Bands;
|
||||
|
||||
if(toOverlay.channels() == 3){ //non transparent image, use black as mask
|
||||
cvtColor(toOverlay,toOverlayGRAY, COLOR_BGR2GRAY); //picture to greyscale
|
||||
threshold(toOverlayGRAY, mask, 0, 255, THRESH_BINARY); //greyscale to alpha (black or not)
|
||||
} else if (toOverlay.channels() == 4){ //transparent, use alpha layer as mask
|
||||
split(toOverlay,Bands); // seperate channels
|
||||
Mat channels[3] = { Bands[0],Bands[1],Bands[2] };
|
||||
merge(channels,3,toOverlay); // glue together again
|
||||
mask = Bands[3]; // png's alpha channel used as mask
|
||||
}
|
||||
toOverlay.copyTo(input(cv::Rect(0,0,toOverlay.cols, toOverlay.rows)),mask);
|
||||
return input;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
set(uiElements_source_files
|
||||
uiElements.cpp
|
||||
uiElements.hpp
|
||||
)
|
||||
MESSAGE(STATUS "building uiElements")
|
||||
add_library(uiElements ${uiElements_source_files})
|
||||
|
||||
SET("OpenCV_DIR" "/usr/local/lib/")
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
|
||||
MESSAGE(STATUS "Include dirs ${OpenCV_INCLUDE_DIRS}")
|
||||
MESSAGE(STATUS "LINK LIBRARIES ${OpenCV_LIBS}")
|
||||
|
||||
target_link_libraries(uiElements OpenCV)
|
||||
MESSAGE(STATUS "Done building uiElements")
|
@ -0,0 +1 @@
|
||||
#include "./uiElements.hpp"
|
@ -0,0 +1,42 @@
|
||||
#include <opencv4/opencv2/opencv.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
//base UI element class (abstract)
|
||||
struct UiElement{
|
||||
unsigned int xPosPixels;
|
||||
unsigned int yPosPixels;
|
||||
void drawSelf(Mat &input);
|
||||
};
|
||||
//sized ui element (abstract)
|
||||
struct SizedUiElement : UiElement{
|
||||
unsigned int widthPixels;
|
||||
unsigned int heightPixels;
|
||||
void drawSelf(Mat &input);
|
||||
};
|
||||
|
||||
struct UiRect : SizedUiElement{
|
||||
unsigned int borderColor;
|
||||
unsigned int fillingColor;
|
||||
void drawSelf(Mat &input);
|
||||
};
|
||||
|
||||
struct UiText : UiElement{
|
||||
std::string text;
|
||||
unsigned int fontSize;
|
||||
cv::Scalar textColor;
|
||||
cv::HersheyFonts font = HersheyFonts::FONT_HERSHEY_SIMPLEX;
|
||||
unsigned int thickness;
|
||||
unsigned int lineType = 0;
|
||||
bool leftOrigin = false;
|
||||
void drawSelf(cv::Mat &input){
|
||||
putText(input, UiText::text, Point(xPosPixels,yPosPixels), cv::FONT_HERSHEY_DUPLEX, fontSize, textColor, thickness, lineType, leftOrigin);
|
||||
}
|
||||
};
|
||||
//menu item container
|
||||
struct UiMenuItem{
|
||||
std::vector<UiElement> elements;
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
#include "_ui.hpp"
|
||||
|
||||
namespace ui{
|
||||
vector<Ui*> UiManager::managedUIs;
|
||||
|
||||
//initializes the ui manager, following default values
|
||||
void UiManager::init(){
|
||||
waitKey(1);
|
||||
for(int i=0; i<DEFAULT_UI_WINDOW_AMOUNT; i++){
|
||||
Ui* newUI = new Ui();
|
||||
cout << "creating UI n°" << to_string(i) << endl;
|
||||
newUI->myWindow = "project- UI"+std::to_string(i);
|
||||
|
||||
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);
|
||||
|
||||
cout << "window: " << newUI->myWindow << " created at " << DEFAULT_UI_OFFSET_X+i*960 << " , " << DEFAULT_UI_OFFSET_Y << endl;
|
||||
|
||||
managedUIs.push_back(newUI); //add new ui in the ui map, mapped to the window's name
|
||||
}
|
||||
}
|
||||
|
||||
void UiManager::cleanup(){
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#include "helloLibrary/Class1.h"
|
||||
|
||||
using namespace helloLibrary;
|
||||
|
||||
Class1::Class1(string text)
|
||||
{
|
||||
_text = text;
|
||||
}
|
||||
|
||||
string Class1::GetText()
|
||||
{
|
||||
return _text;
|
||||
}
|
Loading…
Reference in new issue