mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 20:46:52 +03:00
nightly
This commit is contained in:
@@ -13,7 +13,11 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
|
||||
|
||||
## Change log - latest version
|
||||
|
||||
##### Rolling (2020-08-17)
|
||||
##### Rolling (2020-08-23)
|
||||
|
||||
* Preparation for web configuration
|
||||
|
||||
* Security Issue: Remove access to "wlan.ini"
|
||||
|
||||
* Only editor for config.ini
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "server_help.h"
|
||||
|
||||
#include "Helper.h"
|
||||
|
||||
/* Max length a file path can have on storage */
|
||||
// #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
|
||||
#define FILE_PATH_MAX (255)
|
||||
@@ -154,6 +156,8 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
|
||||
|
||||
/* Iterate over all files / folders and fetch their names and sizes */
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strcmp("wlan.ini", entry->d_name) != 0 ) // wlan.ini soll nicht angezeigt werden!
|
||||
{
|
||||
entrytype = (entry->d_type == DT_DIR ? "directory" : "file");
|
||||
|
||||
strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len);
|
||||
@@ -185,6 +189,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
|
||||
httpd_resp_sendstr_chunk(req, "\"><button type=\"submit\">Delete</button></form>");
|
||||
httpd_resp_sendstr_chunk(req, "</td></tr>\n");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
/* Finish the file list table */
|
||||
@@ -214,7 +219,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
|
||||
const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
|
||||
req->uri + sizeof("/fileserver") - 1, sizeof(filepath));
|
||||
|
||||
printf("1 uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath);
|
||||
printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath);
|
||||
|
||||
// filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
|
||||
// req->uri, sizeof(filepath));
|
||||
@@ -231,7 +236,10 @@ static esp_err_t download_get_handler(httpd_req_t *req)
|
||||
return http_resp_dir_html(req, filepath);
|
||||
}
|
||||
|
||||
if (stat(filepath, &file_stat) == -1) {
|
||||
std::string testwlan = toUpper(std::string(filename));
|
||||
|
||||
if ((stat(filepath, &file_stat) == -1) || (testwlan.compare("/WLAN.INI") == 0 )) { // wlan.ini soll nicht angezeigt werden!
|
||||
|
||||
/* If file not present on SPIFFS check if URI
|
||||
* corresponds to one of the hardcoded paths */
|
||||
ESP_LOGE(TAG, "Failed to stat file : %s", filepath);
|
||||
@@ -248,6 +256,8 @@ static esp_err_t download_get_handler(httpd_req_t *req)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t res = httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
|
||||
set_content_type_from_file(req, filename);
|
||||
|
||||
|
||||
@@ -113,8 +113,20 @@ void CopyFile(string input, string output)
|
||||
input = FormatFileName(input);
|
||||
output = FormatFileName(output);
|
||||
|
||||
if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0)
|
||||
{
|
||||
printf("wlan.ini kann nicht kopiert werden!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char cTemp;
|
||||
FILE* fpSourceFile = fopen(input.c_str(), "rb");
|
||||
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
|
||||
{
|
||||
printf("File %s existiert nicht!\n", input.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* fpTargetFile = fopen(output.c_str(), "wb");
|
||||
|
||||
// Code Section
|
||||
@@ -384,6 +384,22 @@ CImageBasis::CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _he
|
||||
this->externalImage = true;
|
||||
}
|
||||
|
||||
void CImageBasis::Contrast(float _contrast) //input range [-100..100]
|
||||
{
|
||||
stbi_uc* p_source;
|
||||
|
||||
float contrast = (_contrast/100) + 1; //convert to decimal & shift range: [0..2]
|
||||
float intercept = 128 * (1 - contrast);
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
p_source = this->rgb_image + (this->channels * (y * this->width + x));
|
||||
for (int channels = 0; channels < this->channels; ++channels)
|
||||
p_source[channels] = (uint8_t) std::min(255, std::max(0, (int) (p_source[channels] * contrast + intercept)));
|
||||
}
|
||||
}
|
||||
|
||||
CImageBasis::~CImageBasis()
|
||||
{
|
||||
if (!this->externalImage)
|
||||
|
||||
@@ -35,6 +35,7 @@ class CImageBasis
|
||||
void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
|
||||
void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
|
||||
void setPixelColor(int x, int y, int r, int g, int b);
|
||||
void Contrast(float _contrast);
|
||||
|
||||
|
||||
CImageBasis();
|
||||
|
||||
@@ -24,7 +24,7 @@ board_build.embed_files =
|
||||
;board_build.partitions = partitions_singleapp.csv
|
||||
board_build.partitions = partition.csv
|
||||
|
||||
lib_deps = connect_wlan, conversions, driver, sensors, jomjol_image_proc, jomjol_controlcamera, jomjol_flowcontroll, jomjol_tfliteclass, tfmicro, jomjol_fileserver_ota, jomjol_time_sntp, jomjol_logfile
|
||||
lib_deps = jomjol_helper, connect_wlan, conversions, driver, sensors, jomjol_image_proc, jomjol_controlcamera, jomjol_flowcontroll, jomjol_tfliteclass, tfmicro, jomjol_fileserver_ota, jomjol_time_sntp, jomjol_logfile
|
||||
monitor_speed = 115200
|
||||
|
||||
debug_tool = esp-prog
|
||||
|
||||
@@ -138,8 +138,12 @@ esp_err_t hello_main_handler(httpd_req_t *req)
|
||||
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
esp_err_t res;
|
||||
res = httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
if (res != ESP_OK)
|
||||
return res;
|
||||
|
||||
esp_err_t res = send_file(req, filetosend, &file_stat);
|
||||
res = send_file(req, filetosend, &file_stat);
|
||||
if (res != ESP_OK)
|
||||
return res;
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include "Helper.h"
|
||||
|
||||
#include "esp_camera.h"
|
||||
#include "time_sntp.h"
|
||||
#include "ClassControllCamera.h"
|
||||
@@ -125,6 +127,7 @@ esp_err_t handler_doflow(httpd_req_t *req)
|
||||
|
||||
|
||||
|
||||
|
||||
esp_err_t handler_wasserzaehler(httpd_req_t *req)
|
||||
{
|
||||
LogFile.WriteToFile("handler_wasserzaehler");
|
||||
@@ -215,6 +218,121 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
|
||||
|
||||
|
||||
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
|
||||
return ESP_OK;
|
||||
};
|
||||
|
||||
|
||||
esp_err_t handler_editflow(httpd_req_t *req)
|
||||
{
|
||||
LogFile.WriteToFile("handler_editflow");
|
||||
const char* resp_str;
|
||||
string zw;
|
||||
bool _rawValue = false;
|
||||
|
||||
printf("handler_editflow uri:\n"); printf(req->uri); printf("\n");
|
||||
|
||||
char _query[200];
|
||||
char _valuechar[30];
|
||||
string _task;
|
||||
|
||||
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
|
||||
{
|
||||
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
|
||||
{
|
||||
printf("task is found"); printf(_valuechar); printf("\n");
|
||||
_task = string(_valuechar);
|
||||
}
|
||||
}
|
||||
|
||||
if (_task.compare("copy") == 0)
|
||||
{
|
||||
string in, out, zw;
|
||||
|
||||
httpd_query_key_value(_query, "in", _valuechar, 30);
|
||||
in = string(_valuechar);
|
||||
printf("in: "); printf(in.c_str()); printf("\n");
|
||||
|
||||
httpd_query_key_value(_query, "out", _valuechar, 30);
|
||||
out = string(_valuechar);
|
||||
printf("out: "); printf(out.c_str()); printf("\n");
|
||||
|
||||
in = "/sdcard" + in;
|
||||
out = "/sdcard" + out;
|
||||
|
||||
CopyFile(in, out);
|
||||
zw = "Copy Done";
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
}
|
||||
|
||||
|
||||
if (_task.compare("cutref") == 0)
|
||||
{
|
||||
string in, out, zw;
|
||||
int x, y, dx, dy;
|
||||
bool enhance = false;
|
||||
|
||||
httpd_query_key_value(_query, "in", _valuechar, 30);
|
||||
in = string(_valuechar);
|
||||
printf("in: "); printf(in.c_str()); printf("\n");
|
||||
|
||||
httpd_query_key_value(_query, "out", _valuechar, 30);
|
||||
out = string(_valuechar);
|
||||
printf("out: "); printf(out.c_str()); printf("\n");
|
||||
|
||||
httpd_query_key_value(_query, "x", _valuechar, 30);
|
||||
zw = string(_valuechar);
|
||||
x = stoi(zw);
|
||||
printf("x: "); printf(zw.c_str()); printf("\n");
|
||||
|
||||
httpd_query_key_value(_query, "y", _valuechar, 30);
|
||||
zw = string(_valuechar);
|
||||
y = stoi(zw);
|
||||
printf("y: "); printf(zw.c_str()); printf("\n");
|
||||
|
||||
httpd_query_key_value(_query, "dx", _valuechar, 30);
|
||||
zw = string(_valuechar);
|
||||
dx = stoi(zw);
|
||||
printf("dx: "); printf(zw.c_str()); printf("\n");
|
||||
|
||||
httpd_query_key_value(_query, "dy", _valuechar, 30);
|
||||
zw = string(_valuechar);
|
||||
dy = stoi(zw);
|
||||
printf("dy: "); printf(zw.c_str()); printf("\n");
|
||||
|
||||
if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
|
||||
{
|
||||
zw = string(_valuechar);
|
||||
if (zw.compare("true") == 0)
|
||||
{
|
||||
enhance = true;
|
||||
}
|
||||
}
|
||||
|
||||
in = "/sdcard" + in;
|
||||
out = "/sdcard" + out;
|
||||
|
||||
string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
|
||||
|
||||
CAlignAndCutImage *caic = new CAlignAndCutImage(in);
|
||||
caic->CutAndSave(out2, x, y, dx, dy);
|
||||
delete caic;
|
||||
|
||||
CImageBasis *cim = new CImageBasis(out2);
|
||||
if (enhance)
|
||||
{
|
||||
cim->Contrast(90);
|
||||
}
|
||||
|
||||
cim->SaveToFile(out);
|
||||
delete cim;
|
||||
|
||||
zw = "CutImage Done";
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
}
|
||||
|
||||
/* Respond with an empty chunk to signal HTTP response completion */
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
|
||||
@@ -321,6 +439,12 @@ void register_server_tflite_uri(httpd_handle_t server)
|
||||
camuri.user_ctx = (void*) "Light Off";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
|
||||
camuri.uri = "/editflow.html";
|
||||
camuri.handler = handler_editflow;
|
||||
camuri.user_ctx = (void*) "EditFlow";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
camuri.uri = "/wasserzaehler.html";
|
||||
camuri.handler = handler_wasserzaehler;
|
||||
camuri.user_ctx = (void*) "Wasserzaehler";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user