Просмотр исходного кода

Waitmissing for missing memory

jomjol 5 лет назад
Родитель
Сommit
7e4f83c2f5

+ 1 - 1
code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp

@@ -116,7 +116,7 @@ string ClassFlowAlignment::getHTMLSingleStep(string host)
 bool ClassFlowAlignment::doFlow(string time) 
 {
     if (!ImageTMP) 
-        ImageTMP = new CImageBasis(ImageBasis);
+        ImageTMP = new CImageBasis(ImageBasis, 5);
 
     if (AlignAndCutImage)
         delete AlignAndCutImage;

+ 1 - 1
code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp

@@ -23,7 +23,7 @@ void ClassFlowAnalog::SetInitialParameter(void)
     modelysize = 1;
     ListFlowControll = NULL;
     previousElement = NULL;   
-    SaveAllFiles = true; 
+    SaveAllFiles = false; 
 }   
 
 ClassFlowAnalog::ClassFlowAnalog(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)

+ 0 - 5
code/components/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -202,15 +202,11 @@ bool ClassFlowControll::doFlow(string time)
 
 
 /////////////////////////////////////////////////////
-    int aInternalFreeHeapSizeAtEnd, aInternalFreeHeapSizeAtStart;
-    aInternalFreeHeapSizeAtStart = getInternalESPHeapSize(); 
-
     if (flowcontrolldebugdetail){
         std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Start: " + getESPHeapInfo();
         LogFile.WriteToFile(aStartEspInfoStr);
     }    
 
-    aInternalFreeHeapSizeAtEnd = getInternalESPHeapSize(); 
     if (flowcontrolldebugdetail){
         std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
         LogFile.WriteToFile(aStartEspInfoStr);
@@ -241,7 +237,6 @@ bool ClassFlowControll::doFlow(string time)
             result = true;
         }
 
-        aInternalFreeHeapSizeAtEnd = getInternalESPHeapSize(); 
         if (flowcontrolldebugdetail){
             std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
             LogFile.WriteToFile(aStartEspInfoStr);

+ 1 - 1
code/components/jomjol_flowcontroll/ClassFlowDigit.cpp

@@ -24,7 +24,7 @@ void ClassFlowDigit::SetInitialParameter(void)
     modelysize = 1;
     ListFlowControll = NULL;
     previousElement = NULL;    
-    SaveAllFiles = true;
+    SaveAllFiles = false;
 }    
 
 ClassFlowDigit::ClassFlowDigit() : ClassFlowImage(TAG)

+ 13 - 1
code/components/jomjol_image_proc/CImageBasis.cpp

@@ -283,7 +283,7 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
 
 }
 
-CImageBasis::CImageBasis(CImageBasis *_copyfrom)
+CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat) 
 {
     externalImage = false;
     channels = _copyfrom->channels;
@@ -293,6 +293,18 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom)
 
     int memsize = width * height * channels;
     rgb_image = (unsigned char*)GET_MEMORY(memsize);
+
+    int anz = 1;
+    TickType_t xDelay;
+    while (!rgb_image && (anz < _anzrepeat))    
+    {
+		    printf("Create Image from Copy - Speicher ist voll - Versuche es erneut: %d.\n", anz);
+        xDelay = 1000 / portTICK_PERIOD_MS;
+        rgb_image = (unsigned char*) malloc(memsize);
+        anz++;
+    }
+
+    
     if (!rgb_image)
     {
         printf(getESPHeapInfo().c_str());

+ 1 - 1
code/components/jomjol_image_proc/CImageBasis.h

@@ -65,7 +65,7 @@ class CImageBasis
         CImageBasis(std::string _image);
         CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
         CImageBasis(int _width, int _height, int _channels);
-        CImageBasis(CImageBasis *_copyfrom);
+        CImageBasis(CImageBasis *_copyfrom, int _anzrepeat = 0);
 
         void Resize(int _new_dx, int _new_dy);        
         void Resize(int _new_dx, int _new_dy, CImageBasis *_target);        

+ 17 - 76
code/components/jomjol_tfliteclass/CTfLiteClass.cpp

@@ -1,9 +1,8 @@
 #include "CTfLiteClass.h"
 
-#include "bitmap_image.hpp"
+// #include "bitmap_image.hpp"
 
 #include "ClassLogFile.h"
-
 #include "Helper.h"
 
 #include <sys/stat.h>
@@ -33,20 +32,6 @@ int CTfLiteClass::GetClassFromImageBasis(CImageBasis *rs)
     return GetOutClassification();
 }
 
-
-int CTfLiteClass::GetClassFromImage(std::string _fn)
-{
-//  printf("Before Load image %s\n", _fn.c_str());
-    if (!LoadInputImage(_fn))
-      return -1000;
-//  printf("After Load image %s\n", _fn.c_str());
-
-    Invoke();
-  printf("After Invoke %s\n", _fn.c_str());
-
-    return GetOutClassification();
-}
-
 int CTfLiteClass::GetOutClassification()
 {
   TfLiteTensor* output2 = interpreter->output(0);
@@ -128,13 +113,10 @@ void CTfLiteClass::Invoke()
 bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
 {
     std::string zw = "ClassFlowAnalog::doNeuralNetwork nach LoadInputResizeImage: ";
-//    LogFile.WriteToFile(zw);
-
 
     unsigned int w = rs->width;
     unsigned int h = rs->height;
     unsigned char red, green, blue;
-
 //    printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
 
     input_i = 0;
@@ -152,49 +134,6 @@ bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
                 input_data_ptr++;
                 *(input_data_ptr) = (float) blue;
                 input_data_ptr++;
-
-//                printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue);
-
-            }
-    
-    if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
-
-    return true;
-}
-
-
-
-bool CTfLiteClass::LoadInputImage(std::string _fn)
-{
-    std::string zw = "ClassFlowAnalog::doNeuralNetwork nach Load Image: " + _fn;
-//    LogFile.WriteToFile(zw);
-    bitmap_image image(_fn);
-    if (debugdetailtflite) LogFile.WriteToFile(zw);
-
-    unsigned int w = image.width();
-    unsigned int h = image.height();
-    unsigned char red, green, blue;
-
-//    printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
-
-    input_i = 0;
-    float* input_data_ptr = (interpreter->input(0))->data.f;
-
-    for (int y = 0; y < h; ++y)
-        for (int x = 0; x < w; ++x)
-            {
-                red = image.red_channel(x, y);
-                green = image.green_channel(x, y);
-                blue = image.blue_channel(x, y);
-                *(input_data_ptr) = (float) red;
-                input_data_ptr++;
-                *(input_data_ptr) = (float) green;
-                input_data_ptr++;
-                *(input_data_ptr) = (float) blue;
-                input_data_ptr++;
-
-//                printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue);
-
             }
     
     if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
@@ -205,7 +144,6 @@ bool CTfLiteClass::LoadInputImage(std::string _fn)
 
 void CTfLiteClass::MakeAllocate()
 {
-//    static tflite::ops::micro::AllOpsResolver resolver;
     static tflite::AllOpsResolver resolver;
     this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
 
@@ -215,7 +153,6 @@ void CTfLiteClass::MakeAllocate()
     this->GetInputDimension();   
     return;
   }
-
 //    printf("Allocate Done.\n");
 }
 
@@ -223,8 +160,6 @@ void CTfLiteClass::GetInputTensorSize(){
     float *zw = this->input;
     int test = sizeof(zw);
     printf("Input Tensor Dimension: %d\n", test);       
-
-    printf("Input Tensor Dimension: %d\n", test);   
 }
 
 long CTfLiteClass::GetFileSize(std::string filename)
@@ -239,7 +174,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
 {
     long size;
     
-    size = this->GetFileSize(_fn);
+    size = GetFileSize(_fn);
 
     if (size == -1)
     {
@@ -247,16 +182,25 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
         return NULL;
     }
 
-
     unsigned char *result = (unsigned char*) malloc(size);
+    int anz = 1;
+    TickType_t xDelay;
+    while (!result && (anz < 6))    // maximal 5x versuchen (= 5s)
+    {
+		    printf("Speicher ist voll - Versuche es erneut: %d.\n", anz);
+        xDelay = 1000 / portTICK_PERIOD_MS;
+        result = (unsigned char*) malloc(size);
+        anz++;
+    }
+
   
-	if(result != NULL) {
+	  if(result != NULL) {
 //		printf("\nSpeicher ist reserviert\n");
         FILE* f = OpenFileAndWait(_fn.c_str(), "rb");     // vorher  nur "r"
         fread(result, 1, size, f);
         fclose(f);        
-	}else {
-		printf("\nKein freier Speicher vorhanden.\n");
+	  }else {
+		  printf("\nKein freier Speicher vorhanden.\n");
 	}    
 
 
@@ -272,14 +216,11 @@ void CTfLiteClass::LoadModel(std::string _fn){
 #endif
 
     unsigned char *rd;
-    rd = this->ReadFileToCharArray(_fn.c_str());
-//    printf("loadedfile: %d", (int) rd);
+    rd = ReadFileToCharArray(_fn.c_str());
 
     this->model = tflite::GetModel(rd);
     free(rd);
     TFLITE_MINIMAL_CHECK(model != nullptr); 
-//    printf("tfile Loaded.\n");  
-
 }
 
 
@@ -308,6 +249,6 @@ namespace tflite {
     return 0;
   }
 
-}  // namespace tflite
+}  
 
 

+ 0 - 3
code/components/jomjol_tfliteclass/CTfLiteClass.h

@@ -41,7 +41,6 @@ class CTfLiteClass
         const tflite::Model* model;
         tflite::MicroInterpreter* interpreter;
         TfLiteTensor* output = nullptr;     
-//        static tflite::ops::micro::AllOpsResolver *resolver; 
         static tflite::AllOpsResolver resolver;
 
         int kTensorArenaSize;
@@ -60,12 +59,10 @@ class CTfLiteClass
         void LoadModel(std::string _fn);
         void MakeAllocate();
         void GetInputTensorSize();
-        bool LoadInputImage(std::string _fn);
         bool LoadInputImageBasis(CImageBasis *rs);
         void Invoke();
         void GetOutPut();
         int GetOutClassification();
-        int GetClassFromImage(std::string _fn);
         int GetClassFromImageBasis(CImageBasis *rs);
 
         float GetOutputValue(int nr);

+ 1 - 3
code/main/server_main.cpp

@@ -141,7 +141,6 @@ esp_err_t starttime_get_handler(httpd_req_t *req)
 esp_err_t hello_main_handler(httpd_req_t *req)
 {
     char filepath[50];
-    struct stat file_stat;
     printf("uri: %s\n", req->uri);
     int _pos;
     esp_err_t res;
@@ -196,7 +195,6 @@ esp_err_t hello_main_handler(httpd_req_t *req)
 esp_err_t img_tmp_handler(httpd_req_t *req)
 {
     char filepath[50];
-    struct stat file_stat;
     printf("uri: %s\n", req->uri);
 
     char *base_path = (char*) req->user_ctx;
@@ -236,7 +234,7 @@ esp_err_t img_tmp_virtual_handler(httpd_req_t *req)
 
     if (filetosend == "raw.jpg")
     {
-        return GetRawJPG(req);
+        return GetRawJPG(req); 
     } 
 
     esp_err_t zw = GetJPG(filetosend, req);

+ 2 - 2
code/main/version.cpp

@@ -1,4 +1,4 @@
-const char* GIT_REV="b418525";
+const char* GIT_REV="9971c82";
 const char* GIT_TAG="";
 const char* GIT_BRANCH="rolling-reduce-sd-use";
-const char* BUILD_TIME="2020-12-23 07:56";
+const char* BUILD_TIME="2020-12-23 10:06";

+ 2 - 2
code/version.cpp

@@ -1,4 +1,4 @@
-const char* GIT_REV="b418525";
+const char* GIT_REV="9971c82";
 const char* GIT_TAG="";
 const char* GIT_BRANCH="rolling-reduce-sd-use";
-const char* BUILD_TIME="2020-12-23 07:56";
+const char* BUILD_TIME="2020-12-23 10:06";

BIN
firmware/bootloader.bin


BIN
firmware/firmware.bin


BIN
firmware/html.zip