From 27dccb247f9aa93b0aa8be827e4d977e92c2cb5d Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Wed, 6 May 2020 15:57:39 +0200 Subject: [PATCH] change structure --- Makefile | 11 ++---- README.md | 8 +++++ app/Makefile | 16 +++++++++ .../SandboxSetupApp.cpp | 2 +- export.sh | 8 ----- {includes => inc}/beamer.h | 0 {includes => inc}/beamerProjection.h | 0 {includes => inc}/borderedit.h | 0 {includes => inc}/camera.h | 0 includes/controller.h => inc/sandbox.h | 8 ++--- {includes => inc}/sandboxConfig.h | 0 {includes => inc}/sandboxSetup.h | 0 includes/borderfinder.h | 19 ---------- includes/log.h | 11 ------ includes/sandbox.h | 22 ------------ sandbox.h | 35 +++++++++++++++++++ src/Makefile | 9 +++-- src/{core => }/components/Makefile | 2 +- src/{core => }/components/beamer.cpp | 2 +- .../components/beamerProjection.cpp | 2 +- src/{core => }/components/camera.cpp | 2 +- src/core/Makefile | 21 ----------- src/core/tools/Makefile | 19 ---------- src/lib/Makefile | 12 +++++++ src/{core/controller.cpp => lib/sandbox.cpp} | 20 +++++------ src/{ => lib}/sandboxSetup.cpp | 4 +-- src/sandbox.cpp | 29 --------------- src/tools/Makefile | 12 +++++++ src/{core => }/tools/borderedit.cpp | 3 +- src/{core => }/tools/sandboxConfig.cpp | 2 +- 30 files changed, 113 insertions(+), 166 deletions(-) create mode 100644 README.md create mode 100644 app/Makefile rename SandboxSetupApp.cpp => app/SandboxSetupApp.cpp (78%) delete mode 100644 export.sh rename {includes => inc}/beamer.h (100%) rename {includes => inc}/beamerProjection.h (100%) rename {includes => inc}/borderedit.h (100%) rename {includes => inc}/camera.h (100%) rename includes/controller.h => inc/sandbox.h (90%) rename {includes => inc}/sandboxConfig.h (100%) rename {includes => inc}/sandboxSetup.h (100%) delete mode 100644 includes/borderfinder.h delete mode 100644 includes/log.h delete mode 100644 includes/sandbox.h create mode 100644 sandbox.h rename src/{core => }/components/Makefile (83%) rename src/{core => }/components/beamer.cpp (99%) rename src/{core => }/components/beamerProjection.cpp (98%) rename src/{core => }/components/camera.cpp (99%) delete mode 100644 src/core/Makefile delete mode 100644 src/core/tools/Makefile create mode 100644 src/lib/Makefile rename src/{core/controller.cpp => lib/sandbox.cpp} (83%) rename src/{ => lib}/sandboxSetup.cpp (94%) delete mode 100644 src/sandbox.cpp create mode 100644 src/tools/Makefile rename src/{core => }/tools/borderedit.cpp (96%) rename src/{core => }/tools/sandboxConfig.cpp (99%) diff --git a/Makefile b/Makefile index 3a783bf..0d470a3 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ include src/common.mk include dep.mk OBJSALL=$(shell find src -name '*.o') -SETUPAPP=SandboxSetupApp LIBNAME=libsandbox LIB_MINOR_VERS=0.0 @@ -14,7 +13,7 @@ all: $(MAKE) -C src $(MAKE) pack -C . $(MAKE) link -C . - $(MAKE) app -C . + $(MAKE) -C app pack: gcc -shared -Wl,-soname,$(LIB_FULL_NAME) -o $(LIB_FULL_NAME) $(OBJSALL) @@ -23,14 +22,8 @@ link: -ln -s $(LIB_FULL_NAME) $(LIBNAME).so.$(LIB_MAJOR_VERS) -ln -s $(LIB_FULL_NAME) $(LIBNAME).so -app: $(SETUPAPP).o $(LIBNAME).so - g++ $< -o $(SETUPAPP) -L. -lsandbox $(DEP_SANDBOX) - -$(SETUPAPP).o: $(SETUPAPP).cpp - $(CCP) $(CFLAGS) -I./includes -c $< -o $@ - - clean: -rm -f *.o *.so* -rm $(SETUPAPP) $(MAKE) clean -C src + $(MAKE) clean -C app diff --git a/README.md b/README.md new file mode 100644 index 0000000..e63e727 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Library Sandbox + +## Before launching your application + - LD_LIBRARY_PATH must contain dir's path to libsandbox.so + - Enter this command in the terminal where you are using your application + +REALTIVE_PATH_TO_SO=../ar_sandbox_lib && \ +export LD_LIBRARY_PATH=$(pwd)/$REALTIVE_PATH_TO_SO diff --git a/app/Makefile b/app/Makefile new file mode 100644 index 0000000..435e3ed --- /dev/null +++ b/app/Makefile @@ -0,0 +1,16 @@ +include ../src/common.mk +include ../dep.mk + +SETUPAPP=SandboxSetupApp +LIB_PATH=.. + + +app: $(SETUPAPP).o + g++ $< -o $(SETUPAPP) -L$(LIB_PATH) -lsandbox $(DEP_SANDBOX) + +$(SETUPAPP).o: $(SETUPAPP).cpp + $(CCP) $(CFLAGS) -I$(LIB_PATH)/inc -c $< -o $@ + +clean: + -rm -f *.o + -rm $(SETUPAPP) diff --git a/SandboxSetupApp.cpp b/app/SandboxSetupApp.cpp similarity index 78% rename from SandboxSetupApp.cpp rename to app/SandboxSetupApp.cpp index 52aebe5..78c5484 100644 --- a/SandboxSetupApp.cpp +++ b/app/SandboxSetupApp.cpp @@ -1,4 +1,4 @@ -#include "includes/sandboxSetup.h" +#include "../inc/sandboxSetup.h" int main(){ diff --git a/export.sh b/export.sh deleted file mode 100644 index e8758b0..0000000 --- a/export.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -## Usable script for now -## LD_LIBRARY_PATH must contain dir's path to libsandbox.so -## Do the cmd in your terminal - -REALTIVE_PATH_TO_SO=../ar_sandbox_lib && \ -export LD_LIBRARY_PATH=$(pwd)/$REALTIVE_PATH_TO_SO diff --git a/includes/beamer.h b/inc/beamer.h similarity index 100% rename from includes/beamer.h rename to inc/beamer.h diff --git a/includes/beamerProjection.h b/inc/beamerProjection.h similarity index 100% rename from includes/beamerProjection.h rename to inc/beamerProjection.h diff --git a/includes/borderedit.h b/inc/borderedit.h similarity index 100% rename from includes/borderedit.h rename to inc/borderedit.h diff --git a/includes/camera.h b/inc/camera.h similarity index 100% rename from includes/camera.h rename to inc/camera.h diff --git a/includes/controller.h b/inc/sandbox.h similarity index 90% rename from includes/controller.h rename to inc/sandbox.h index 2b6f555..b6c62b4 100644 --- a/includes/controller.h +++ b/inc/sandbox.h @@ -1,5 +1,5 @@ -#ifndef CONTROLLER_H -#define CONTROLLER_H +#ifndef SANDBOX_H +#define SANDBOX_H #include <opencv2/opencv.hpp> #include "camera.h" @@ -8,7 +8,7 @@ #include "borderedit.h" #include "sandboxConfig.h" -class Controller +class Sandbox { private: static const int ESCAPE_CHAR = 27; @@ -21,7 +21,7 @@ class Controller void showImage(cv::Mat* image, char *windowName); public: - Controller(); + Sandbox(); cv::Mat getRGBFrame(); cv::Mat getDepthFrame(); cv::Mat* adjustProjection(cv::Mat* frame); diff --git a/includes/sandboxConfig.h b/inc/sandboxConfig.h similarity index 100% rename from includes/sandboxConfig.h rename to inc/sandboxConfig.h diff --git a/includes/sandboxSetup.h b/inc/sandboxSetup.h similarity index 100% rename from includes/sandboxSetup.h rename to inc/sandboxSetup.h diff --git a/includes/borderfinder.h b/includes/borderfinder.h deleted file mode 100644 index 78aed1c..0000000 --- a/includes/borderfinder.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef BORDERFINDER_H -#define BORDERFINDER_H -#include <opencv2/opencv.hpp> -class BorderFinder -{ -private: - // helper function: - // finds a cosine of angle between vectors - // from pt0->pt1 and from pt0->pt2 - double angle(cv::Point pt1, cv::Point pt2, cv::Point pt0); - cv::Mat frameImage; - cv::Rect rotateRect(cv::Rect rect, int heightPercentage, int widthPercetange); - -public: - float calculDistance(float point1[], float point2[]); - BorderFinder(cv::Mat frame); - bool find(cv::Rect &rect); -}; -#endif \ No newline at end of file diff --git a/includes/log.h b/includes/log.h deleted file mode 100644 index e984b7b..0000000 --- a/includes/log.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef LOG_H -#define LOG_H -#define LOG_NONE 0x0 -#define LOG_DEBUG 0x1 -#define LOG_WARNING 0x2 -#define LOG_ERROR 0x4 -extern int log_level; -void error(char*msg); -void mylog(int log_level, const char *format,...); - -#endif /* LOG_H */ \ No newline at end of file diff --git a/includes/sandbox.h b/includes/sandbox.h deleted file mode 100644 index 594fca6..0000000 --- a/includes/sandbox.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SANDBOX_H -#define SANDBOX_H - -#include <opencv2/opencv.hpp> -#include "controller.h" - -class Sandbox -{ - private: - Controller controller; - - public: - Sandbox(); - cv::Mat getRGBFrame(); - cv::Mat getDepthFrame(); - cv::Mat* adjustProjection(cv::Mat* frame); - void initWindowsFullScreen(); - void showImage(cv::Mat* image); - int loadConfig(); - -}; -#endif diff --git a/sandbox.h b/sandbox.h new file mode 100644 index 0000000..b6c62b4 --- /dev/null +++ b/sandbox.h @@ -0,0 +1,35 @@ +#ifndef SANDBOX_H +#define SANDBOX_H + +#include <opencv2/opencv.hpp> +#include "camera.h" +#include "beamerProjection.h" +#include "beamer.h" +#include "borderedit.h" +#include "sandboxConfig.h" + +class Sandbox +{ + private: + static const int ESCAPE_CHAR = 27; + char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml"; + char *defaultWindowsName = (char*) "ShowApp"; + BeamerProjection projection; + Camera camera; + Beamer beamer; + void initWindowsFullScreen(char *windowName); + void showImage(cv::Mat* image, char *windowName); + + public: + Sandbox(); + cv::Mat getRGBFrame(); + cv::Mat getDepthFrame(); + cv::Mat* adjustProjection(cv::Mat* frame); + void showImage(cv::Mat* image); + int loadConfig(); + int loadConfigFrom(char *path); + void initWindowsFullScreen(); + +}; + +#endif diff --git a/src/Makefile b/src/Makefile index 7a03607..970c5cc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,8 +4,9 @@ SRCS:=$(wildcard *.cpp) OBJS:=$(SRCS:%.cpp=%.o) all: - $(MAKE) -C core - $(MAKE) build -C . + $(MAKE) -C components + $(MAKE) -C tools + $(MAKE) -C lib build: $(OBJS) @@ -14,4 +15,6 @@ build: $(OBJS) clean: -rm -f *.o - $(MAKE) clean -C core + $(MAKE) clean -C components + $(MAKE) clean -C tools + $(MAKE) clean -C lib diff --git a/src/core/components/Makefile b/src/components/Makefile similarity index 83% rename from src/core/components/Makefile rename to src/components/Makefile index c621ec2..28a1f3a 100644 --- a/src/core/components/Makefile +++ b/src/components/Makefile @@ -1,4 +1,4 @@ -include ../../common.mk +include ../common.mk SRCS=$(wildcard *.cpp) OBJS=$(SRCS:%.cpp=%.o) diff --git a/src/core/components/beamer.cpp b/src/components/beamer.cpp similarity index 99% rename from src/core/components/beamer.cpp rename to src/components/beamer.cpp index 97d2aa7..f291e02 100644 --- a/src/core/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -1,4 +1,4 @@ -#include "../../../includes/beamer.h" +#include "../../inc/beamer.h" using namespace cv; using namespace std; diff --git a/src/core/components/beamerProjection.cpp b/src/components/beamerProjection.cpp similarity index 98% rename from src/core/components/beamerProjection.cpp rename to src/components/beamerProjection.cpp index f6047fa..527ddc0 100644 --- a/src/core/components/beamerProjection.cpp +++ b/src/components/beamerProjection.cpp @@ -1,4 +1,4 @@ -#include "../../../includes/beamerProjection.h" +#include "../../inc/beamerProjection.h" using namespace cv; using namespace std; diff --git a/src/core/components/camera.cpp b/src/components/camera.cpp similarity index 99% rename from src/core/components/camera.cpp rename to src/components/camera.cpp index 0c9f430..fe19cd8 100644 --- a/src/core/components/camera.cpp +++ b/src/components/camera.cpp @@ -1,4 +1,4 @@ -#include "../../../includes/camera.h" +#include "../../inc/camera.h" using namespace cv; Camera::Camera() { diff --git a/src/core/Makefile b/src/core/Makefile deleted file mode 100644 index caad237..0000000 --- a/src/core/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../common.mk - -SRCS:=$(wildcard *.cpp) -OBJS:=$(SRCS:%.cpp=%.o) - -all: - $(MAKE) -C components - $(MAKE) -C tools - $(MAKE) build -C . - -build: $(OBJS) - -%.o: %.cpp - g++ $(CFLAGS) -c $< -o $@ - -clean: - -rm -f *.o - $(MAKE) clean -C components - $(MAKE) clean -C tools - - diff --git a/src/core/tools/Makefile b/src/core/tools/Makefile deleted file mode 100644 index a422e9b..0000000 --- a/src/core/tools/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../../common.mk - -SRCS_C=$(wildcard *.c) -OBJS_C=$(SRCS_C:%.c=%.o) -SRCS_CPP=$(wildcard *.cpp) -OBJS_CPP=$(SRCS_CPP:%.cpp=%.o) - -build: $(OBJS_C) $(OBJS_CPP) - -%.o: %.cpp - g++ $(CFLAGS) -c $< -o $@ - -%.o: %.c - gcc -Wall -Wextra -std=gnu11 -fPIC -c $< -o $@ - -clean: - -rm -f *.o - - diff --git a/src/lib/Makefile b/src/lib/Makefile new file mode 100644 index 0000000..28a1f3a --- /dev/null +++ b/src/lib/Makefile @@ -0,0 +1,12 @@ +include ../common.mk + +SRCS=$(wildcard *.cpp) +OBJS=$(SRCS:%.cpp=%.o) + +build: $(OBJS) + +%.o: %.cpp + g++ -c $(CFLAGS) $< -o $@ + +clean: + -rm -f *.o diff --git a/src/core/controller.cpp b/src/lib/sandbox.cpp similarity index 83% rename from src/core/controller.cpp rename to src/lib/sandbox.cpp index 39f745a..7ad9b83 100644 --- a/src/core/controller.cpp +++ b/src/lib/sandbox.cpp @@ -1,4 +1,4 @@ -#include "../../includes/controller.h" +#include "../../inc/sandbox.h" #include <numeric> #include <fstream> #include <string> @@ -10,7 +10,7 @@ using namespace std; * MAIN */ -Controller::Controller(){ +Sandbox::Sandbox(){ camera.startAlign(); } @@ -19,18 +19,18 @@ Controller::Controller(){ * PUBLIC */ -cv::Mat Controller::getRGBFrame(){ +cv::Mat Sandbox::getRGBFrame(){ camera.captureFramesAlign(); return camera.getRGBFrameAlign()(camera.getCroppingMask()); } -cv::Mat Controller::getDepthFrame(){ +cv::Mat Sandbox::getDepthFrame(){ camera.captureFramesAlign(); return camera.getDepthFrameAlign()(camera.getCroppingMask()); } -cv::Mat* Controller::adjustProjection(cv::Mat* frame){ +cv::Mat* Sandbox::adjustProjection(cv::Mat* frame){ static cv::Mat frameBeamer(cv::Size(beamer.getWidth(), beamer.getHeight()), CV_8UC3); @@ -48,14 +48,14 @@ cv::Mat* Controller::adjustProjection(cv::Mat* frame){ return frame; } -void Controller::showImage(cv::Mat* image){ +void Sandbox::showImage(cv::Mat* image){ initWindowsFullScreen(defaultWindowsName); adjustProjection(image); cv::imshow(defaultWindowsName, *image); } -int Controller::loadConfigFrom(char *path){ +int Sandbox::loadConfigFrom(char *path){ int err = SandboxConfig::loadAdjustingMatrixInto(path, &projection); if(err){ return err; } @@ -66,7 +66,7 @@ int Controller::loadConfigFrom(char *path){ return 0; } -int Controller::loadConfig(){ +int Sandbox::loadConfig(){ std::cout << "Config loading..." << std::endl; @@ -86,7 +86,7 @@ int Controller::loadConfig(){ return 0; } -void Controller::initWindowsFullScreen(){ +void Sandbox::initWindowsFullScreen(){ initWindowsFullScreen(defaultWindowsName); } @@ -95,7 +95,7 @@ void Controller::initWindowsFullScreen(){ * PRIVATE */ -void Controller::initWindowsFullScreen(char *windowName){ +void Sandbox::initWindowsFullScreen(char *windowName){ cv::namedWindow(windowName, CV_WINDOW_NORMAL); cv::setWindowProperty(windowName, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); } \ No newline at end of file diff --git a/src/sandboxSetup.cpp b/src/lib/sandboxSetup.cpp similarity index 94% rename from src/sandboxSetup.cpp rename to src/lib/sandboxSetup.cpp index 36e95dd..1489581 100644 --- a/src/sandboxSetup.cpp +++ b/src/lib/sandboxSetup.cpp @@ -1,4 +1,4 @@ -#include "../includes/sandboxSetup.h" +#include "../../inc/sandboxSetup.h" @@ -44,13 +44,11 @@ void SandboxSetup::setupProjection(){ float y = coloredFrame.size().height; float x = coloredFrame.size().width; std::vector<cv::Point> rectPoints{ cv::Point(1.0/4*x, 1.0/4*y), cv::Point(1.0/4*x, 3.0/4*y), cv::Point(3.0/4*x, 3.0/4*y), cv::Point(3.0/4*x, 1.0/4*y) }; - std::cout << "Edit Rectangle" << std::endl; BorderEdit::edit(coloredFrame, &rectPoints); // edit projected frame // Set adjusting matrix for the projection int widthTop = rectPoints[3].x - rectPoints[0].x; double angle1 = atan((double)(rectPoints[3].y - rectPoints[0].y) / widthTop); - std::cout << "Calibrate Rotation Matrixe" << std::endl; cv::Mat matRotation = cv::getRotationMatrix2D(center, toDegrees(angle1), 1); // adjustingMatrix projection.setAdjustingMatrix(matRotation); diff --git a/src/sandbox.cpp b/src/sandbox.cpp deleted file mode 100644 index 292c1d3..0000000 --- a/src/sandbox.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "../includes/sandbox.h" - -Sandbox::Sandbox(){ - -} - -cv::Mat Sandbox::getRGBFrame(){ - return controller.getDepthFrame(); -} - -cv::Mat Sandbox::getDepthFrame(){ - return controller.getDepthFrame(); -} - -cv::Mat* Sandbox::adjustProjection(cv::Mat* frame){ - return controller.adjustProjection(frame); -} - -void Sandbox::initWindowsFullScreen(){ - controller.initWindowsFullScreen(); -} - -void Sandbox::showImage(cv::Mat* image){ - controller.showImage(image); -} - -int Sandbox::loadConfig(){ - return controller.loadConfig(); -} \ No newline at end of file diff --git a/src/tools/Makefile b/src/tools/Makefile new file mode 100644 index 0000000..28a1f3a --- /dev/null +++ b/src/tools/Makefile @@ -0,0 +1,12 @@ +include ../common.mk + +SRCS=$(wildcard *.cpp) +OBJS=$(SRCS:%.cpp=%.o) + +build: $(OBJS) + +%.o: %.cpp + g++ -c $(CFLAGS) $< -o $@ + +clean: + -rm -f *.o diff --git a/src/core/tools/borderedit.cpp b/src/tools/borderedit.cpp similarity index 96% rename from src/core/tools/borderedit.cpp rename to src/tools/borderedit.cpp index 35caa4c..c4dd842 100644 --- a/src/core/tools/borderedit.cpp +++ b/src/tools/borderedit.cpp @@ -1,5 +1,4 @@ -#include <algorithm> -#include "../../../includes/borderedit.h" +#include "../../inc/borderedit.h" using namespace std; using namespace cv; diff --git a/src/core/tools/sandboxConfig.cpp b/src/tools/sandboxConfig.cpp similarity index 99% rename from src/core/tools/sandboxConfig.cpp rename to src/tools/sandboxConfig.cpp index 65c30a5..11a6c6c 100644 --- a/src/core/tools/sandboxConfig.cpp +++ b/src/tools/sandboxConfig.cpp @@ -1,4 +1,4 @@ -#include "../../../includes/sandboxConfig.h" +#include "../../inc/sandboxConfig.h" static int saveConfigIn(char *path, YAML::Node config); -- GitLab