diff --git a/Makefile b/Makefile index 3a783bf3e11b15a729c15fc00bcab9e03ee2e9ba..0d470a3c4be8f778497d3c8bc5df601878da4a3f 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 0000000000000000000000000000000000000000..e63e7271dbc995abbcceeff65e830cfe2fcd3cd8 --- /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 0000000000000000000000000000000000000000..435e3ed1a95a9bec48267c52c3d6fe44ad56b7e6 --- /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 52aebe5b15e8506673d54b46e8bdabb22df6c299..78c5484bf801013bc8f9c8606c10d04955b180f9 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 e8758b05a40084eb3575fe21532259fe3fa7f41c..0000000000000000000000000000000000000000 --- 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 2b6f55589224d73a79f7cb619a4867613b1d2a72..b6c62b47a04c02a06f9f33a5387fcbaf84ce7cc5 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 78aed1cb4c674861d828d3ca32eef6891a32b99b..0000000000000000000000000000000000000000 --- 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 e984b7bc4d5076a4b10e2638d02b1b6002491e09..0000000000000000000000000000000000000000 --- 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 594fca61a5d463eb666180bb37964fc2d2b69aa0..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..b6c62b47a04c02a06f9f33a5387fcbaf84ce7cc5 --- /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 7a036077a6d6afcf7fbc49725b341e1a46b18156..970c5ccc321b8ed325a09311f6ec74d8261dd6d1 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 c621ec261d64dead6bf551778b303c676a0485ac..28a1f3a96f85deef07681ea7947157b41763e123 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 97d2aa72a88611fd38364a070d8107cb225f61d7..f291e02c2d4246a5103a10718a7f77a5d6c55aa7 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 f6047fa2c2baead6ae80e08f43f76901e876fa26..527ddc04db575cfec4c1eb7b5350f42c294dbaeb 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 0c9f43083e48f128379d34e8a66cd0daf94ee920..fe19cd8bc5562854707a1d89b816d3c3da8908cc 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 caad237c0536988d90049e5a46c554bd4139deb7..0000000000000000000000000000000000000000 --- 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 a422e9b1db9a31b453e794bb8484b18a5a8834b6..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..28a1f3a96f85deef07681ea7947157b41763e123 --- /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 39f745a9055fc78b68d5f5f0bcf1f940cb480fce..7ad9b831de04522c5b827eb7d59214ea34ba5075 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 36e95dd10d0286327e4d76529f99ded19c1529a9..14895817f5511658c1815b5a3e46b2cefef2a483 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 292c1d3204665a2a8239b3c5382f308ad854a8ba..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..28a1f3a96f85deef07681ea7947157b41763e123 --- /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 35caa4c239d0cb1e4630d86f8248f3dad1e5ac98..c4dd84289eeff9cd5bdbc6034e0baabf975641e5 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 65c30a50c533cc91e7772aa45c2824260f53c2af..11a6c6c4f297b073a264fba5d9ee284127307adb 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);