diff --git a/.gitignore b/.gitignore index d936712c..442c2cf4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .pio/ .vscode/ .code-workspace -.helper/ /sd-card/htm./.vscode/ /code/build diff --git a/code/.helper/makezip.bat b/code/.helper/makezip.bat new file mode 100644 index 00000000..713ed3e7 --- /dev/null +++ b/code/.helper/makezip.bat @@ -0,0 +1 @@ +powershell Compress-Archive "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\sd-card\html\*" "C:\Users\Muell\Documents\Programmieren\GitHub\AI-on-the-edge-device\firmware\html.zip" \ No newline at end of file diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 5a421512..d2e044b3 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -136,18 +136,34 @@ static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size return len; } -void CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation) +bool CCamera::SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation) { + bool result = false; sensor_t * s = esp_camera_sensor_get(); _brightness = min(2, max(-2, _brightness)); -// _contrast = min(2, max(-2, _contrast)); + _contrast = min(2, max(-2, _contrast)); // _saturation = min(2, max(-2, _saturation)); // s->set_saturation(s, _saturation); -// s->set_contrast(s, _contrast); + s->set_contrast(s, _contrast); s->set_brightness(s, _brightness); -} + if (_brightness != brightness) + result = true; + if (_contrast != contrast) + result = true; + if (_saturation != saturation) + result = true; + + brightness = _brightness; + contrast = _contrast; + saturation = _saturation; + + if (result && isFixedExposure) + EnableAutoExposure(waitbeforepicture_org); + + return result; +} void CCamera::SetQualitySize(int qual, framesize_t resol) @@ -194,6 +210,31 @@ void CCamera::SetQualitySize(int qual, framesize_t resol) } +void CCamera::EnableAutoExposure(int flashdauer) +{ + LEDOnOff(true); + LightOnOff(true); + const TickType_t xDelay = flashdauer / portTICK_PERIOD_MS; + vTaskDelay( xDelay ); + + camera_fb_t * fb = esp_camera_fb_get(); + if (!fb) { + ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed"); + } + esp_camera_fb_return(fb); + + sensor_t * s = esp_camera_sensor_get(); + s->set_gain_ctrl(s, 0); + s->set_exposure_ctrl(s, 0); + + + LEDOnOff(false); + LightOnOff(false); + isFixedExposure = true; + waitbeforepicture_org = flashdauer; +} + + esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) { @@ -236,7 +277,7 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) LogFile.WriteHeapInfo("CCamera::CaptureToBasisImage - After fb_get"); #endif - LEDOnOff(false); + LEDOnOff(false); if (delay > 0) LightOnOff(false); @@ -526,6 +567,10 @@ CCamera::CCamera() #ifdef DEBUG_DETAIL_ON printf("CreateClassCamera\n"); #endif + brightness = -5; + contrast = -5; + saturation = -5; + isFixedExposure = false; } esp_err_t CCamera::InitCam() diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.h b/code/components/jomjol_controlcamera/ClassControllCamera.h index 6cdbaa73..b4389b8a 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.h +++ b/code/components/jomjol_controlcamera/ClassControllCamera.h @@ -23,6 +23,9 @@ class CCamera { protected: int ActualQuality; framesize_t ActualResolution; + int brightness, contrast, saturation; + bool isFixedExposure; + int waitbeforepicture_org; public: int image_height, image_width; @@ -34,9 +37,12 @@ class CCamera { void LEDOnOff(bool status); esp_err_t CaptureToHTTP(httpd_req_t *req, int delay = 0); void SetQualitySize(int qual, framesize_t resol); - void SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation); + bool SetBrightnessContrastSaturation(int _brightness, int _contrast, int _saturation); void GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol); + void EnableAutoExposure(int flashdauer); + + framesize_t TextToFramesize(const char * text); esp_err_t CaptureToFile(std::string nm, int delay = 0); diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp index fd20986b..9b86f3da 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp @@ -34,6 +34,7 @@ void ClassFlowMakeImage::SetInitialParameter(void) ImageSize = FRAMESIZE_VGA; SaveAllFiles = false; disabled = false; + FixedExposure = false; namerawimage = "/sdcard/img_tmp/raw.jpg"; } @@ -97,6 +98,11 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) _saturation = stoi(zerlegt[1]); } + if ((toUpper(zerlegt[0]) == "FIXEDEXPOSURE") && (zerlegt.size() > 1)) + { + if (toUpper(zerlegt[1]) == "TRUE") + FixedExposure = true; + } } Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation); @@ -107,6 +113,18 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) rawImage = new CImageBasis(); rawImage->CreateEmptyImage(image_width, image_height, 3); + waitbeforepicture_store = waitbeforepicture; + if (FixedExposure) + { + printf("Fixed Exposure enabled!\n"); + int flashdauer = (int) (waitbeforepicture * 1000); + Camera.EnableAutoExposure(flashdauer); + waitbeforepicture = 0.2; +// flashdauer = (int) (waitbeforepicture * 1000); +// takePictureWithFlash(flashdauer); +// rawImage->SaveToFile("/sdcard/init2.jpg"); + } + return true; } @@ -121,7 +139,7 @@ bool ClassFlowMakeImage::doFlow(string zwtime) { string logPath = CreateLogFolder(zwtime); - int flashdauer = (int) waitbeforepicture * 1000; + int flashdauer = (int) (waitbeforepicture * 1000); #ifdef DEBUG_DETAIL_ON LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash"); @@ -146,7 +164,7 @@ bool ClassFlowMakeImage::doFlow(string zwtime) esp_err_t ClassFlowMakeImage::SendRawJPG(httpd_req_t *req) { - int flashdauer = (int) waitbeforepicture * 1000; + int flashdauer = (int) (waitbeforepicture * 1000); return Camera.CaptureToHTTP(req, flashdauer); } @@ -155,7 +173,7 @@ ImageData* ClassFlowMakeImage::SendRawImage() { CImageBasis *zw = new CImageBasis(rawImage); ImageData *id; - int flashdauer = (int) waitbeforepicture * 1000; + int flashdauer = (int) (waitbeforepicture * 1000); Camera.CaptureToBasisImage(zw, flashdauer); id = zw->writeToMemoryAsJPG(); delete zw; diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h index 744c2cd3..4150cf7f 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h @@ -15,6 +15,7 @@ class ClassFlowMakeImage : { protected: float waitbeforepicture; + float waitbeforepicture_store; framesize_t ImageSize; bool isImageSize; int ImageQuality; @@ -22,6 +23,8 @@ protected: string namerawimage; int image_height, image_width; bool SaveAllFiles; + bool FixedExposure; + void CopyFile(string input, string output); @@ -29,6 +32,7 @@ protected: esp_err_t camera_capture(); void takePictureWithFlash(int flashdauer); + void SetInitialParameter(void); public: diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 786e7ff6..f7f9e32a 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -429,7 +429,7 @@ esp_err_t handler_editflow(httpd_req_t *req) // printf("Parameter host: "); printf(_host.c_str()); printf("\n"); // string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str()); - Camera.SetBrightnessContrastSaturation(bri, con, sat); + bool changed = Camera.SetBrightnessContrastSaturation(bri, con, sat); std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host); httpd_resp_sendstr_chunk(req, zw.c_str()); } diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 37802ebf..719e8d7a 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -209,6 +209,7 @@ esp_err_t hello_main_handler(httpd_req_t *req) return res; /* Respond with an empty chunk to signal HTTP response completion */ +// httpd_resp_sendstr(req, ""); httpd_resp_send_chunk(req, NULL, 0); #ifdef DEBUG_DETAIL_ON diff --git a/code/main/version.cpp b/code/main/version.cpp index 7b38c088..0207574a 100644 --- a/code/main/version.cpp +++ b/code/main/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="8720211"; +const char* GIT_REV="9dbad05"; const char* GIT_TAG=""; -const char* GIT_BRANCH="rolling"; -const char* BUILD_TIME="2021-02-03 21:16"; \ No newline at end of file +const char* GIT_BRANCH="rolling-camera-speedup"; +const char* BUILD_TIME="2021-02-21 21:40"; \ No newline at end of file diff --git a/code/version.cpp b/code/version.cpp index 7b38c088..0207574a 100644 --- a/code/version.cpp +++ b/code/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="8720211"; +const char* GIT_REV="9dbad05"; const char* GIT_TAG=""; -const char* GIT_BRANCH="rolling"; -const char* BUILD_TIME="2021-02-03 21:16"; \ No newline at end of file +const char* GIT_BRANCH="rolling-camera-speedup"; +const char* BUILD_TIME="2021-02-21 21:40"; \ No newline at end of file diff --git a/firmware/bootloader.bin b/firmware/bootloader.bin index c1a68508..7842d22f 100644 Binary files a/firmware/bootloader.bin and b/firmware/bootloader.bin differ diff --git a/firmware/firmware.bin b/firmware/firmware.bin index f8dc5c80..3f2d67e1 100644 Binary files a/firmware/firmware.bin and b/firmware/firmware.bin differ diff --git a/firmware/html.zip b/firmware/html.zip index 4b78f3a1..c55827af 100644 Binary files a/firmware/html.zip and b/firmware/html.zip differ diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index 841b261d..c379db37 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -16,7 +16,7 @@ AlignmentAlgo = Default [Digits] -Model = /config/dig0721s1.tflite +Model = /config/dig0811s1.tflite ;LogImageLocation = /log/digit ;LogfileRetentionInDays = 3 ModelInputSize = 20 32 diff --git a/sd-card/config/dig0810s3.tflite b/sd-card/config/dig0810s3.tflite new file mode 100644 index 00000000..d9464658 Binary files /dev/null and b/sd-card/config/dig0810s3.tflite differ diff --git a/sd-card/config/dig0811s1.tflite b/sd-card/config/dig0811s1.tflite new file mode 100644 index 00000000..8a78aed4 Binary files /dev/null and b/sd-card/config/dig0811s1.tflite differ diff --git a/sd-card/html/debug.log b/sd-card/html/debug.log deleted file mode 100644 index c2a5e456..00000000 --- a/sd-card/html/debug.log +++ /dev/null @@ -1,7 +0,0 @@ -[1204/185120.033:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3) -[0102/122131.430:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3) -[0118/210038.095:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3) -[0122/182642.937:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3) -[0122/191644.620:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3) -[0122/214224.255:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3) -[0123/204102.088:ERROR:directory_reader_win.cc(43)] FindFirstFile: Das System kann den angegebenen Pfad nicht finden. (0x3)