From 091aa463efa4a75b8c55f509337e125bb8907f97 Mon Sep 17 00:00:00 2001
From: "simon.fanetti" <simon.fanetti@etu.hesge.ch>
Date: Tue, 11 Aug 2020 15:42:49 +0200
Subject: [PATCH] add reading perf file app

---
 display_levels/Makefile           |  4 +--
 display_levels/display_levels.cpp | 44 ++++++-------------------------
 display_levels/sandbox_conf.yaml  |  4 +--
 test_perf/read_output.py          | 39 +++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 40 deletions(-)
 create mode 100644 test_perf/read_output.py

diff --git a/display_levels/Makefile b/display_levels/Makefile
index 9b7a7de..82f5ef5 100644
--- a/display_levels/Makefile
+++ b/display_levels/Makefile
@@ -1,6 +1,6 @@
-include ../../../ar_sandbox_lib/dep.mk
+include ../../ar_sandbox_lib/dep.mk
 
-API_PATH=../../../ar_sandbox_lib
+API_PATH=../../ar_sandbox_lib
 CFLAGS=-std=c++11 -Wall -Wextra -g
 CCP=g++
 DBG_GPROF=-pg
diff --git a/display_levels/display_levels.cpp b/display_levels/display_levels.cpp
index f5b1f6a..5e25ca4 100644
--- a/display_levels/display_levels.cpp
+++ b/display_levels/display_levels.cpp
@@ -7,12 +7,7 @@
 int main(){
 
     Sandbox sandbox;
-    
-    // Default
-    char *sandbox_conf_file = (char*)"../../sandbox_conf.yaml";
-  
-    // Debug
-    //char * sandbox_conf_file = (char *)"../../../sandbox_conf.yaml";
+    char *sandbox_conf_file = (char*)"./sandbox_conf.yaml";
 
     if(sandbox.loadConfig(sandbox_conf_file)){
         std::cout << "Failed to load the configuration" << std::endl;
@@ -43,52 +38,29 @@ void displayLevels(Sandbox &sandbox, float top, float height){
     cv::setWindowProperty(windowName, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
     
     sandbox.captureFrame();
-    cv::Mat depth_cache = sandbox.getDepthFrame(); 
-    cv::Mat new_depth = cv::Mat(depth_cache.size(), CV_32F);
-    cv::Mat colorized = cv::Mat(depth_cache.size(), CV_8UC3);
-    cv::Mat_<cv::Vec3b> res = cv::Mat(depth_cache.size(), CV_8UC3);
+    cv::Mat1f depth_cache = sandbox.getDepthFrame(); 
+    cv::Mat1f new_depth = cv::Mat(depth_cache.size(), CV_32F);
+    cv::Mat3b colorized = cv::Mat(depth_cache.size(), CV_8UC3);
+    cv::Mat3b res = cv::Mat(depth_cache.size(), CV_8UC3);
     
     //cv::Mat_<cv::Vec3b> img = cv::imread("index.png");
 
-
-    //std::chrono::milliseconds start_ms = std::chrono::duration_cast< std::chrono::milliseconds >( std::chrono::system_clock::now().time_since_epoch() );
-    //int cpt_frame = 0;
-    //double average = 0;
-
     do{
-    //for(int i=0; i<200; i++){
         sandbox.captureFrame();
         new_depth = sandbox.getDepthFrame();
+        // don't show what is above the top of sandox
+        depth_cache.copyTo( new_depth, (new_depth < top) );
+        // don't update little differences due to the camera depth captors
         new_depth.copyTo( depth_cache, (cv::abs(depth_cache-new_depth) > DEPTH_MARGIN_ERROR) );
 
         colorized = colorizeDepth(depth_cache, top, height);
         cv::cvtColor(colorized, res, CV_RGB2BGR);
 
-        //std::chrono::milliseconds start_adj_ms = std::chrono::duration_cast< std::chrono::milliseconds >( std::chrono::system_clock::now().time_since_epoch() );
-        //cv::Mat_<cv::Vec3b> result = sandbox.adjustProjection(res);
-        
-        //std::chrono::milliseconds now_adj_ms = std::chrono::duration_cast< std::chrono::milliseconds >( std::chrono::system_clock::now().time_since_epoch() );
-        //int time = (now_adj_ms - start_adj_ms).count();
-        //average += time;
-        //std::cout << time << std::endl;
-
         res = sandbox.adjustProjection(res, depth_cache);
         cv::imshow(windowName, res);
 
-        /*
-        cpt_frame++;
-        std::chrono::milliseconds now_ms = std::chrono::duration_cast< std::chrono::milliseconds >( std::chrono::system_clock::now().time_since_epoch() );
-        if(now_ms-start_ms > std::chrono::milliseconds(1000)){
-            std::cout << cpt_frame << std::endl;
-            cpt_frame = 0;
-            start_ms = std::chrono::duration_cast< std::chrono::milliseconds >( std::chrono::system_clock::now().time_since_epoch() );
-        }
-        */
-
-    //}
     } while (cv::waitKey(10) != ESCAPE_CHAR);
 
-    //std::cout << "Average " << average/200 << std::endl;
     cv::destroyAllWindows();
 
 }
diff --git a/display_levels/sandbox_conf.yaml b/display_levels/sandbox_conf.yaml
index 7b1aa6f..752bef5 100644
--- a/display_levels/sandbox_conf.yaml
+++ b/display_levels/sandbox_conf.yaml
@@ -11,8 +11,8 @@ CroppingMask:
   width: 452
   height: 338
 BeamerResolution:
-  width: 1024
-  height: 768
+  width: 1400
+  height: 1050
 BeamerPosition:
   x: 0.05
   y: 0.2
diff --git a/test_perf/read_output.py b/test_perf/read_output.py
new file mode 100644
index 0000000..a155945
--- /dev/null
+++ b/test_perf/read_output.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+import sys
+
+times = [0,0,0,0]
+average = times
+average_fps = 0
+cnt = 0
+
+if(len(sys.argv) < 2):
+    print("Use case : ./exec [output_file_name]")
+    exit()
+
+with open(sys.argv[1]) as file:
+
+    lines = file.readlines()
+    for i in range(1, len(lines)):
+        line = lines[i]
+        cnt += 1
+        str_values = line.split(",")
+        values = [ int(v.rstrip("\n")) for v in str_values ]
+        for n in range(0, len(times)):
+            times[n] += values[n]
+
+
+if(cnt > 0):
+    average = [ float(time)/cnt for time in times ]
+    average_fps = 1000.0 / sum(average)
+
+
+print("Average times in ms :")
+print("Capture : {}".format(average[0]))
+print("Get depth frame : {}".format(average[1]))
+print("Get color frame : {}".format(average[2]))
+print("Adjust frame : {}".format(average[3]))
+print("With an average fps of : {}".format(average_fps))
+
+
+
-- 
GitLab