From 20213e247e95bc4dd0f8f2c6460c5c56c3059792 Mon Sep 17 00:00:00 2001
From: "simon.fanetti" <simon.fanetti@etu.hesge.ch>
Date: Wed, 6 May 2020 15:58:40 +0200
Subject: [PATCH] adjust app to lib

---
 Makefile          | 10 ++++-
 app.cpp           | 97 +++++++++++++++++++++++++++++------------------
 beamer_config.sh  |  4 +-
 sandbox_conf.yaml | 13 +++++++
 4 files changed, 85 insertions(+), 39 deletions(-)
 create mode 100644 sandbox_conf.yaml

diff --git a/Makefile b/Makefile
index ad0a554..4144bb0 100644
--- a/Makefile
+++ b/Makefile
@@ -4,11 +4,19 @@ API_PATH=../ar_sandbox_lib
 CFLAGS=-std=c++11 -Wall -Wextra -g
 CCP=g++
 
+all: app
+
 app: app.o
 	$(CCP) $^ -o $@ -L$(API_PATH) -lsandbox $(DEP_SANDBOX)
 
 %.o: %.cpp
-	$(CCP) $(CFLAGS) -I$(API_PATH)/includes -c $< -o $@ 
+	$(CCP) $(CFLAGS) -I$(API_PATH)/inc -c $< -o $@ 
+
+run:
+	./app
+
+setup:
+	$(API_PATH)/app/SandboxSetupApp
 
 clean:
 	rm -f *.o app
diff --git a/app.cpp b/app.cpp
index 0f62cdc..9d39c03 100644
--- a/app.cpp
+++ b/app.cpp
@@ -1,5 +1,5 @@
 
-#include "../ar_sandbox_lib/includes/sandbox.h"
+#include "../ar_sandbox_lib/sandbox.h"
 #include <numeric>
 #include <fstream>
 #include <string>
@@ -10,7 +10,59 @@ using namespace cv;
 
 #define ESCAPE_CHAR 27
 
+
+
+Mat coloredFrame(Mat frameDepth);
+void showLevel();
+void showDiff();
+//vector<int> findCercleZ(Mat &rgb);
+//void trackCircle();
+
+
+
 Sandbox client;
+void (*apps[2])() = {showLevel, showDiff};
+
+int main(int argc, char *argv[])
+{
+    if(client.loadConfig()){
+        std::cout << "Error : Couldn't load the configuration" << std::endl;
+        return 1;
+    }
+
+    showLevel();
+
+    /*cout << "Press: \n 0: Show level \n 1: Show difference \n";
+    int n = 0;
+    cin >> n;
+
+    apps[n]();*/
+}
+
+void showLevel()
+{
+    char windowName[] = "Sandbox";
+    Mat frameData;
+    Mat colored;
+    Mat proj_frame;
+
+    //client.initWindowsFullScreen();
+    cv::namedWindow(windowName, CV_WINDOW_AUTOSIZE);
+
+    do{
+        client.getDepthFrame().copyTo(frameData);   
+        colored = coloredFrame(frameData);
+
+        colored.copyTo(proj_frame);
+        Mat* res = client.adjustProjection(&proj_frame);
+        cv::imshow(windowName, *res);
+
+        //client.showImage(&colored);
+
+    } while (waitKey(10) != ESCAPE_CHAR);
+    
+    cv::destroyAllWindows();
+}
 
 Mat coloredFrame(Mat frameDepth)
 {
@@ -45,29 +97,16 @@ Mat coloredFrame(Mat frameDepth)
             }
         }
     }
-    bitwise_not(depthFrameColored, depthFrameColored); //reverse colormap
-    applyColorMap(depthFrameColored, depthFrameColored, cv::COLORMAP_JET);
+    cv::bitwise_not(depthFrameColored, depthFrameColored); //reverse colormap
+    cv::applyColorMap(depthFrameColored, depthFrameColored, cv::COLORMAP_JET);
     depthFrameColored.setTo(cv::Scalar(0, 0, 0), (frameDepth == 0));
     return depthFrameColored;
 }
 
-void showLevel()
-{
-    //char windowName[] = "Sandbox";
-    Mat frameData;
-    client.getDepthFrame().copyTo(frameData);
-    Mat colored;
-    do
-    {
-        client.getDepthFrame().copyTo(frameData);
-        colored = coloredFrame(frameData);
-        client.showImage(&colored);
-    } while (waitKey(10) != ESCAPE_CHAR);
-    destroyAllWindows();
-}
+void showDiff(){
 /*
-void showDiff(Mat frameBase)
-{
+    Mat frameData;
+    client.getDepthFrame(&frameData);
     Mat frameData;
     client.getDepthFrame(&frameData);
     resize(frameBase, frameBase, frameData.size()); //to match with camera frame
@@ -89,8 +128,10 @@ void showDiff(Mat frameBase)
         keyCode = waitKey(10);
     } while (keyCode!= ESCAPE_CHAR);
     destroyAllWindows();
+    */
 }
 
+/*
 vector<int> findCercleZ(Mat &rgb)
 {
     Mat src_gray;
@@ -136,20 +177,4 @@ void trackCircle()
 
     } while (waitKey(100) != ESCAPE_CHAR);
     destroyAllWindows();
-}*/
-
-int main(int argc, char *argv[])
-{
-    client = Sandbox();
-    cout << "Press: \n 0: Show difference \n 1: Show level \n";
-    int f = 0;
-    cin >> f;
-    if (f == 0)
-    {
-        //Mat frameData;
-        //client.getDepthFrame(&frameData);
-        //showDiff(frameData);
-    }
-    else if (f == 1)
-        showLevel();
-}
\ No newline at end of file
+}*/
\ No newline at end of file
diff --git a/beamer_config.sh b/beamer_config.sh
index 9e02401..8955109 100755
--- a/beamer_config.sh
+++ b/beamer_config.sh
@@ -1,6 +1,6 @@
-SCREEN=DVI-D-0
+SCREEN=eDP-1
 SCN_RES=1920x1080
-BEAMER=HDMI-0
+BEAMER=HDMI-1
 BM_RES=1400x1050
 
 xrandr --output $SCREEN --rate 60 --mode $SCN_RES --fb $SCN_RES --panning $SCN_RES* \
diff --git a/sandbox_conf.yaml b/sandbox_conf.yaml
new file mode 100644
index 0000000..7dd1043
--- /dev/null
+++ b/sandbox_conf.yaml
@@ -0,0 +1,13 @@
+AdjustingMatrix:
+  width: 3
+  height: 2
+  matrix: [1, 0, 0, -0, 1, 0]
+CroppingMask:
+  x: 160
+  y: 120
+  width: 320
+  height: 245
+BeamerPosition:
+  x: 0
+  y: 0
+  z: 0
-- 
GitLab