mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 20:16:55 +03:00
Almost done
This commit is contained in:
@@ -219,10 +219,76 @@ void initialise_wifi_fixed_ip(std::string _ip, std::string _gw, std::string _net
|
||||
|
||||
vEventGroupDelete(wifi_event_group);
|
||||
}
|
||||
///////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
//void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname, std::string &_ip, std::string &_gw, std::string &_netmask, std::string &_dns)
|
||||
|
||||
bool ChangeHostName(std::string fn, std::string _newhostname)
|
||||
{
|
||||
if (_newhostname == hostname)
|
||||
return false;
|
||||
|
||||
string line = "";
|
||||
std::vector<string> zerlegt;
|
||||
|
||||
bool found = false;
|
||||
|
||||
std::vector<string> neuesfile;
|
||||
|
||||
FILE* pFile;
|
||||
fn = FormatFileName(fn);
|
||||
pFile = OpenFileAndWait(fn.c_str(), "r");
|
||||
|
||||
printf("file loaded\n");
|
||||
|
||||
if (pFile == NULL)
|
||||
return false;
|
||||
|
||||
char zw[1024];
|
||||
fgets(zw, 1024, pFile);
|
||||
line = std::string(zw);
|
||||
|
||||
while ((line.size() > 0) || !(feof(pFile)))
|
||||
{
|
||||
printf("%s", line.c_str());
|
||||
zerlegt = ZerlegeZeile(line, "=");
|
||||
zerlegt[0] = trim(zerlegt[0], " ");
|
||||
|
||||
if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){
|
||||
line = "hostname = \"" + _newhostname + "\"\n";
|
||||
found = true;
|
||||
}
|
||||
|
||||
neuesfile.push_back(line);
|
||||
|
||||
if (fgets(zw, 1024, pFile) == NULL)
|
||||
{
|
||||
line = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
line = std::string(zw);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
line = "hostname = \"" + _newhostname + "\"\n";
|
||||
neuesfile.push_back(line);
|
||||
}
|
||||
|
||||
fclose(pFile);
|
||||
|
||||
pFile = OpenFileAndWait(fn.c_str(), "w+");
|
||||
|
||||
for (int i = 0; i < neuesfile.size(); ++i)
|
||||
{
|
||||
fputs(neuesfile[i].c_str(), pFile);
|
||||
}
|
||||
|
||||
fclose(pFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,8 @@ void initialise_wifi_fixed_ip(std::string _ip, std::string _gw, std::string _net
|
||||
void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname);
|
||||
void LoadNetConfigFromFile(std::string fn, std::string &_ip, std::string &_gw, std::string &_netmask, std::string &_dns);
|
||||
|
||||
bool ChangeHostName(std::string fn, std::string _newhostname);
|
||||
|
||||
std::string getHostname();
|
||||
std::string getIPAddress();
|
||||
std::string getSSID();
|
||||
|
||||
@@ -61,53 +61,52 @@ esp_err_t handler_switch_GPIO(httpd_req_t *req)
|
||||
|
||||
gpionum = stoi(gpio);
|
||||
|
||||
// frei: 16; 12-15; 2; 4
|
||||
// frei: 16; 12-15; 2; 4 // nur 12 und 13 funktionieren 2: reboot, 4: BlitzLED, 14/15: DMA für SDKarte ???
|
||||
|
||||
switch (gpionum) {
|
||||
case 2:
|
||||
gpio_num = GPIO_NUM_2;
|
||||
break;
|
||||
case 4:
|
||||
gpio_num = GPIO_NUM_4;
|
||||
break;
|
||||
case 12:
|
||||
gpio_num = GPIO_NUM_12;
|
||||
break;
|
||||
case 13:
|
||||
gpio_num = GPIO_NUM_13;
|
||||
break;
|
||||
case 14:
|
||||
gpio_num = GPIO_NUM_14;
|
||||
break;
|
||||
case 15:
|
||||
gpio_num = GPIO_NUM_15;
|
||||
break;
|
||||
case 16:
|
||||
gpio_num = (gpio_num_t) 16;
|
||||
break;
|
||||
default:
|
||||
zw = "GPIO" + std::to_string(gpionum) + " not support - only 2, 4, 12-16 free";
|
||||
zw = "GPIO" + std::to_string(gpionum) + " not support - only 12 & 13 free";
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Init the GPIO
|
||||
gpio_pad_select_gpio(gpio_num);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT);
|
||||
|
||||
if (status == "HIGH")
|
||||
gpio_set_level(gpio_num, 1);
|
||||
else
|
||||
gpio_set_level(gpio_num, 0);
|
||||
|
||||
|
||||
zw = "GPIO" + std::to_string(gpionum) + " switched to " + status;
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
};
|
||||
|
||||
void initGPIO()
|
||||
{
|
||||
gpio_config_t io_conf;
|
||||
//disable interrupt
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
//set as output mode
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
//bit mask of the pins that you want to set,e.g.GPIO18/19
|
||||
// io_conf.pin_bit_mask = ((1ULL<<GPIO_OUTPUT_IO_0) | (1ULL<<GPIO_OUTPUT_IO_1));
|
||||
// io_conf.pin_bit_mask = ((1ULL << GPIO_NUM_12) | (1ULL << GPIO_NUM_2) | (1ULL << GPIO_NUM_4) | (1ULL << GPIO_NUM_12) | (1ULL << GPIO_NUM_13) | (1ULL << GPIO_NUM_14) | (1ULL << GPIO_NUM_15));
|
||||
io_conf.pin_bit_mask = ((1ULL << GPIO_NUM_12) | (1ULL << GPIO_NUM_13));
|
||||
//disable pull-down mode
|
||||
io_conf.pull_down_en = (gpio_pulldown_t) 0;
|
||||
//disable pull-up mode
|
||||
io_conf.pull_up_en = (gpio_pullup_t) 0;
|
||||
//configure GPIO with the given settings
|
||||
gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
|
||||
void register_server_GPIO_uri(httpd_handle_t server)
|
||||
@@ -120,4 +119,6 @@ void register_server_GPIO_uri(httpd_handle_t server)
|
||||
camuri.handler = handler_switch_GPIO;
|
||||
camuri.user_ctx = (void*) "switch GPIO";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
initGPIO();
|
||||
}
|
||||
|
||||
@@ -65,23 +65,6 @@ static esp_err_t index_html_get_handler(httpd_req_t *req)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Handler to respond with an icon file embedded in flash.
|
||||
* Browsers expect to GET website icon at URI /favicon.ico.
|
||||
* This can be overridden by uploading file with same name */
|
||||
|
||||
/*
|
||||
static esp_err_t favicon_get_handler(httpd_req_t *req)
|
||||
{
|
||||
extern const unsigned char favicon_ico_start[] asm("_binary_favicon_ico_start");
|
||||
extern const unsigned char favicon_ico_end[] asm("_binary_favicon_ico_end");
|
||||
const size_t favicon_ico_size = (favicon_ico_end - favicon_ico_start);
|
||||
httpd_resp_set_type(req, "image/x-icon");
|
||||
httpd_resp_send(req, (const char *)favicon_ico_start, favicon_ico_size);
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
/* Send HTTP response with a run-time generated html consisting of
|
||||
* a list of all files and folders under the requested path.
|
||||
* In case of SPIFFS this returns empty list when path is any
|
||||
|
||||
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources}
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_fileserver_ota jomjol_image_proc)
|
||||
REQUIRES jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_fileserver_ota jomjol_image_proc connect_wlan)
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void ClassFlow::SetInitialParameter(void)
|
||||
{
|
||||
ListFlowControll = NULL;
|
||||
previousElement = NULL;
|
||||
disabled = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,16 +40,18 @@ std::vector<string> ClassFlow::ZerlegeZeile(std::string input, std::string delim
|
||||
|
||||
bool ClassFlow::isNewParagraph(string input)
|
||||
{
|
||||
if (input[0] == '[')
|
||||
if ((input[0] == '[') || ((input[0] == ';') && (input[1] == '[')))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClassFlow::GetNextParagraph(FILE* pfile, string& aktparamgraph)
|
||||
{
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph));
|
||||
while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph));
|
||||
|
||||
if (this->isNewParagraph(aktparamgraph))
|
||||
if (isNewParagraph(aktparamgraph))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -108,7 +111,7 @@ bool ClassFlow::getNextLine(FILE* pfile, string *rt)
|
||||
}
|
||||
*rt = zw;
|
||||
*rt = trim(*rt);
|
||||
while (zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) // Kommentarzeilen (; oder #) und Leerzeilen überspringen
|
||||
while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph
|
||||
{
|
||||
fgets(zw, 1024, pfile);
|
||||
printf("%s", zw);
|
||||
|
||||
@@ -27,7 +27,7 @@ class ClassFlow
|
||||
{
|
||||
protected:
|
||||
// std::vector<string> ZerlegeZeile(string input);
|
||||
std::vector<string> ZerlegeZeile(string input, string delimiter = " =, ");
|
||||
std::vector<string> ZerlegeZeile(string input, string delimiter = " =, \t");
|
||||
bool isNewParagraph(string input);
|
||||
bool GetNextParagraph(FILE* pfile, string& aktparamgraph);
|
||||
bool getNextLine(FILE* pfile, string* rt);
|
||||
@@ -37,6 +37,8 @@ protected:
|
||||
|
||||
virtual void SetInitialParameter(void);
|
||||
|
||||
bool disabled;
|
||||
|
||||
public:
|
||||
ClassFlow(void);
|
||||
ClassFlow(std::vector<ClassFlow*> * lfc);
|
||||
|
||||
@@ -4,29 +4,31 @@
|
||||
|
||||
#include "CRotateImage.h"
|
||||
|
||||
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
|
||||
|
||||
bool AlignmentExtendedDebugging = true;
|
||||
|
||||
#define DEBUG_DETAIL_ON
|
||||
|
||||
|
||||
void ClassFlowAlignment::SetInitialParameter(void)
|
||||
{
|
||||
initalrotate = 0;
|
||||
anz_ref = 0;
|
||||
suchex = 40;
|
||||
suchey = 40;
|
||||
initialmirror = false;
|
||||
SaveAllFiles = false;
|
||||
namerawimage = "/sdcard/img_tmp/raw.jpg";
|
||||
FileStoreRefAlignment = "/sdcard/config/align.txt";
|
||||
ListFlowControll = NULL;
|
||||
AlignAndCutImage = NULL;
|
||||
ImageBasis = NULL;
|
||||
ImageTMP = NULL;
|
||||
previousElement = NULL;
|
||||
ref_dx[0] = 0; ref_dx[1] = 0;
|
||||
ref_dy[0] = 0; ref_dy[1] = 0;
|
||||
disabled = false;
|
||||
SAD_criteria = 0.05;
|
||||
}
|
||||
|
||||
ClassFlowAlignment::ClassFlowAlignment(std::vector<ClassFlow*>* lfc)
|
||||
@@ -53,6 +55,10 @@ ClassFlowAlignment::ClassFlowAlignment(std::vector<ClassFlow*>* lfc)
|
||||
bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
{
|
||||
std::vector<string> zerlegt;
|
||||
int suchex = 40;
|
||||
int suchey = 40;
|
||||
int alg_algo = 0;
|
||||
|
||||
|
||||
aktparamgraph = trim(aktparamgraph);
|
||||
|
||||
@@ -65,29 +71,29 @@ bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||
{
|
||||
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
||||
if ((zerlegt[0] == "InitialMirror") && (zerlegt.size() > 1))
|
||||
zerlegt = ZerlegeZeile(aktparamgraph);
|
||||
if ((toUpper(zerlegt[0]) == "INITIALMIRROR") && (zerlegt.size() > 1))
|
||||
{
|
||||
if (toUpper(zerlegt[1]) == "TRUE")
|
||||
initialmirror = true;
|
||||
}
|
||||
if (((zerlegt[0] == "InitalRotate") || (zerlegt[0] == "InitialRotate")) && (zerlegt.size() > 1))
|
||||
if (((toUpper(zerlegt[0]) == "INITALROTATE") || (toUpper(zerlegt[0]) == "INITIALROTATE")) && (zerlegt.size() > 1))
|
||||
{
|
||||
this->initalrotate = std::stod(zerlegt[1]);
|
||||
}
|
||||
if ((zerlegt[0] == "SearchFieldX") && (zerlegt.size() > 1))
|
||||
if ((toUpper(zerlegt[0]) == "SEARCHFIELDX") && (zerlegt.size() > 1))
|
||||
{
|
||||
this->suchex = std::stod(zerlegt[1]);
|
||||
suchex = std::stod(zerlegt[1]);
|
||||
}
|
||||
if ((zerlegt[0] == "SearchFieldY") && (zerlegt.size() > 1))
|
||||
if ((toUpper(zerlegt[0]) == "SEARCHFIELDY") && (zerlegt.size() > 1))
|
||||
{
|
||||
this->suchey = std::stod(zerlegt[1]);
|
||||
suchey = std::stod(zerlegt[1]);
|
||||
}
|
||||
if ((zerlegt.size() == 3) && (anz_ref < 2))
|
||||
{
|
||||
reffilename[anz_ref] = FormatFileName("/sdcard" + zerlegt[0]);
|
||||
ref_x[anz_ref] = std::stod(zerlegt[1]);
|
||||
ref_y[anz_ref] = std::stod(zerlegt[2]);
|
||||
References[anz_ref].image_file = FormatFileName("/sdcard" + zerlegt[0]);
|
||||
References[anz_ref].target_x = std::stod(zerlegt[1]);
|
||||
References[anz_ref].target_y = std::stod(zerlegt[2]);
|
||||
anz_ref++;
|
||||
}
|
||||
|
||||
@@ -96,8 +102,33 @@ bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
if (toUpper(zerlegt[1]) == "TRUE")
|
||||
SaveAllFiles = true;
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "ALIGNMENTALGO") && (zerlegt.size() > 1))
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
std::string zw2 = "Alignmentmodus gewählt: " + zerlegt[1];
|
||||
LogFile.WriteToFile(zw2);
|
||||
#endif
|
||||
if (toUpper(zerlegt[1]) == "HIGHACCURACY")
|
||||
alg_algo = 1;
|
||||
if (toUpper(zerlegt[1]) == "FAST")
|
||||
alg_algo = 2;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < anz_ref; ++i)
|
||||
{
|
||||
References[i].search_x = suchex;
|
||||
References[i].search_y = suchey;
|
||||
References[i].fastalg_SAD_criteria = SAD_criteria;
|
||||
References[i].alignment_algo = alg_algo;
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
std::string zw2 = "Alignmentmodus geschrieben: " + std::to_string(alg_algo);
|
||||
LogFile.WriteToFile(zw2);
|
||||
#endif
|
||||
}
|
||||
|
||||
LoadReferenceAlignmentValues();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -136,8 +167,11 @@ bool ClassFlowAlignment::doFlow(string time)
|
||||
if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/rot.jpg"));
|
||||
}
|
||||
|
||||
AlignAndCutImage->Align(reffilename[0], ref_x[0], ref_y[0], reffilename[1], ref_x[1], ref_y[1], suchex, suchey, "");
|
||||
AlignAndCutImage->GetRefSize(ref_dx, ref_dy);
|
||||
if (!AlignAndCutImage->Align(&References[0], &References[1]))
|
||||
{
|
||||
SaveReferenceAlignmentValues();
|
||||
}
|
||||
|
||||
if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/alg.jpg"));
|
||||
|
||||
if (SaveAllFiles)
|
||||
@@ -152,13 +186,138 @@ bool ClassFlowAlignment::doFlow(string time)
|
||||
ImageTMP = NULL;
|
||||
}
|
||||
|
||||
LoadReferenceAlignmentValues();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ClassFlowAlignment::DrawRef(CImageBasis *_zw)
|
||||
|
||||
void ClassFlowAlignment::SaveReferenceAlignmentValues()
|
||||
{
|
||||
_zw->drawRect(ref_x[0], ref_y[0], ref_dx[0], ref_dy[0], 255, 0, 0, 2);
|
||||
_zw->drawRect(ref_x[1], ref_y[1], ref_dx[1], ref_dy[1], 255, 0, 0, 2);
|
||||
FILE* pFile;
|
||||
std::string zwtime, zwvalue;
|
||||
|
||||
pFile = fopen(FileStoreRefAlignment.c_str(), "w");
|
||||
|
||||
if (strlen(zwtime.c_str()) == 0)
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm* timeinfo;
|
||||
char buffer[80];
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
strftime(buffer, 80, "%Y-%m-%d_%H-%M-%S", timeinfo);
|
||||
zwtime = std::string(buffer);
|
||||
}
|
||||
|
||||
fputs(zwtime.c_str(), pFile);
|
||||
fputs("\n", pFile);
|
||||
|
||||
zwvalue = std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_y);
|
||||
zwvalue = zwvalue + "\t" +std::to_string(References[0].fastalg_SAD)+ "\t" +std::to_string(References[0].fastalg_min);
|
||||
zwvalue = zwvalue + "\t" +std::to_string(References[0].fastalg_max)+ "\t" +std::to_string(References[0].fastalg_avg);
|
||||
fputs(zwvalue.c_str(), pFile);
|
||||
fputs("\n", pFile);
|
||||
|
||||
zwvalue = std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_y);
|
||||
zwvalue = zwvalue + "\t" +std::to_string(References[1].fastalg_SAD)+ "\t" +std::to_string(References[1].fastalg_min);
|
||||
zwvalue = zwvalue + "\t" +std::to_string(References[1].fastalg_max)+ "\t" +std::to_string(References[1].fastalg_avg);
|
||||
fputs(zwvalue.c_str(), pFile);
|
||||
fputs("\n", pFile);
|
||||
|
||||
fclose(pFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool ClassFlowAlignment::LoadReferenceAlignmentValues(void)
|
||||
{
|
||||
FILE* pFile;
|
||||
char zw[1024];
|
||||
string zwvalue;
|
||||
std::vector<string> zerlegt;
|
||||
|
||||
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues01");
|
||||
|
||||
pFile = fopen(FileStoreRefAlignment.c_str(), "r");
|
||||
if (pFile == NULL)
|
||||
return false;
|
||||
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues01");
|
||||
|
||||
fgets(zw, 1024, pFile);
|
||||
printf("%s", zw);
|
||||
|
||||
// zwvalue = "LoadReferenceAlignmentValues Time: " + std::string(zw);
|
||||
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zwvalue);
|
||||
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues02");
|
||||
|
||||
fgets(zw, 1024, pFile);
|
||||
zerlegt = ZerlegeZeile(std::string(zw), " \t");
|
||||
if (zerlegt.size() < 6)
|
||||
{
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "Exit 01");
|
||||
fclose(pFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues03");
|
||||
|
||||
References[0].fastalg_x = stoi(zerlegt[0]);
|
||||
References[0].fastalg_y = stoi(zerlegt[1]);
|
||||
References[0].fastalg_SAD = stof(zerlegt[2]);
|
||||
References[0].fastalg_min = stoi(zerlegt[3]);
|
||||
References[0].fastalg_max = stoi(zerlegt[4]);
|
||||
References[0].fastalg_avg = stof(zerlegt[5]);
|
||||
|
||||
fgets(zw, 1024, pFile);
|
||||
zerlegt = ZerlegeZeile(std::string(zw));
|
||||
if (zerlegt.size() < 6)
|
||||
{
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "Exit 02");
|
||||
fclose(pFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues03");
|
||||
|
||||
References[1].fastalg_x = stoi(zerlegt[0]);
|
||||
References[1].fastalg_y = stoi(zerlegt[1]);
|
||||
References[1].fastalg_SAD = stof(zerlegt[2]);
|
||||
References[1].fastalg_min = stoi(zerlegt[3]);
|
||||
References[1].fastalg_max = stoi(zerlegt[4]);
|
||||
References[1].fastalg_avg = stof(zerlegt[5]);
|
||||
|
||||
fclose(pFile);
|
||||
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
std::string _zw = "\tLoadReferences[0]\tx,y:\t" + std::to_string(References[0].fastalg_x) + "\t" + std::to_string(References[0].fastalg_x);
|
||||
_zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[0].fastalg_SAD) + "\t" + std::to_string(References[0].fastalg_min);
|
||||
_zw = _zw + "\t" + std::to_string(References[0].fastalg_max) + "\t" + std::to_string(References[0].fastalg_avg);
|
||||
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw);
|
||||
_zw = "\tLoadReferences[1]\tx,y:\t" + std::to_string(References[1].fastalg_x) + "\t" + std::to_string(References[1].fastalg_x);
|
||||
_zw = _zw + "\tSAD, min, max, avg:\t" + std::to_string(References[1].fastalg_SAD) + "\t" + std::to_string(References[1].fastalg_min);
|
||||
_zw = _zw + "\t" + std::to_string(References[1].fastalg_max) + "\t" + std::to_string(References[1].fastalg_avg);
|
||||
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", _zw);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ClassFlowAlignment::DrawRef(CImageBasis *_zw)
|
||||
{
|
||||
_zw->drawRect(References[0].target_x, References[0].target_y, References[0].width, References[0].height, 255, 0, 0, 2);
|
||||
_zw->drawRect(References[1].target_x, References[1].target_y, References[1].width, References[1].height, 255, 0, 0, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "ClassFlow.h"
|
||||
#include "Helper.h"
|
||||
#include "CAlignAndCutImage.h"
|
||||
#include "CFindTemplate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -14,16 +15,17 @@ class ClassFlowAlignment :
|
||||
protected:
|
||||
float initalrotate;
|
||||
bool initialmirror;
|
||||
string reffilename[2];
|
||||
int ref_x[2], ref_y[2];
|
||||
int ref_dx[2], ref_dy[2];
|
||||
RefInfo References[2];
|
||||
int anz_ref;
|
||||
int suchex, suchey;
|
||||
string namerawimage;
|
||||
bool SaveAllFiles;
|
||||
CAlignAndCutImage *AlignAndCutImage;
|
||||
std::string FileStoreRefAlignment;
|
||||
float SAD_criteria;
|
||||
|
||||
void SetInitialParameter(void);
|
||||
bool LoadReferenceAlignmentValues(void);
|
||||
void SaveReferenceAlignmentValues();
|
||||
|
||||
public:
|
||||
CImageBasis *ImageBasis, *ImageTMP;
|
||||
|
||||
@@ -24,6 +24,8 @@ void ClassFlowAnalog::SetInitialParameter(void)
|
||||
ListFlowControll = NULL;
|
||||
previousElement = NULL;
|
||||
SaveAllFiles = false;
|
||||
disabled = false;
|
||||
|
||||
}
|
||||
|
||||
ClassFlowAnalog::ClassFlowAnalog(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
|
||||
@@ -89,9 +91,18 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
return false;
|
||||
|
||||
|
||||
if (aktparamgraph.compare("[Analog]") != 0) // Paragraph passt nich zu MakeImage
|
||||
if ((aktparamgraph.compare("[Analog]") != 0) && (aktparamgraph.compare(";[Analog]") != 0)) // Paragraph passt nich zu MakeImage
|
||||
return false;
|
||||
|
||||
if (aktparamgraph[0] == ';')
|
||||
{
|
||||
disabled = true;
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph));
|
||||
printf("[Analog] is disabled !!!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||
{
|
||||
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
||||
@@ -171,6 +182,9 @@ string ClassFlowAnalog::getHTMLSingleStep(string host)
|
||||
|
||||
bool ClassFlowAnalog::doFlow(string time)
|
||||
{
|
||||
if (disabled)
|
||||
return true;
|
||||
|
||||
if (!doAlignAndCut(time)){
|
||||
return false;
|
||||
};
|
||||
@@ -186,6 +200,9 @@ bool ClassFlowAnalog::doFlow(string time)
|
||||
|
||||
bool ClassFlowAnalog::doAlignAndCut(string time)
|
||||
{
|
||||
if (disabled)
|
||||
return true;
|
||||
|
||||
CAlignAndCutImage *caic = flowpostalignment->GetAlignAndCutImage();
|
||||
|
||||
for (int i = 0; i < ROI.size(); ++i)
|
||||
@@ -219,6 +236,9 @@ void ClassFlowAnalog::DrawROI(CImageBasis *_zw)
|
||||
|
||||
bool ClassFlowAnalog::doNeuralNetwork(string time)
|
||||
{
|
||||
if (disabled)
|
||||
return true;
|
||||
|
||||
string logPath = CreateLogFolder(time);
|
||||
|
||||
string input = "/sdcard/img_tmp/alg.jpg";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "ClassFlowControll.h"
|
||||
|
||||
#include "connect_wlan.h"
|
||||
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
@@ -19,28 +21,25 @@ static const char* TAG = "flow_controll";
|
||||
std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
|
||||
std::string _classname = "";
|
||||
std::string result = "";
|
||||
if (_stepname.compare("[MakeImage]") == 0){
|
||||
if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){
|
||||
_classname = "ClassFlowMakeImage";
|
||||
}
|
||||
if (_stepname.compare("[Alignment]") == 0){
|
||||
if ((_stepname.compare("[Alignment]") == 0) || (_stepname.compare(";[Alignment]") == 0)){
|
||||
_classname = "ClassFlowAlignment";
|
||||
}
|
||||
if (_stepname.compare("[Digits]") == 0){
|
||||
if ((_stepname.compare("[Digits]") == 0) || (_stepname.compare(";[Digits]") == 0)){
|
||||
_classname = "ClassFlowDigit";
|
||||
}
|
||||
if (_stepname.compare("[Analog]") == 0){
|
||||
if ((_stepname.compare("[Analog]") == 0) || (_stepname.compare(";[Analog]") == 0)){
|
||||
_classname = "ClassFlowAnalog";
|
||||
}
|
||||
if (_stepname.compare("[MQTT]") == 0){
|
||||
if ((_stepname.compare("[MQTT]") == 0) || (_stepname.compare(";[MQTT]") == 0)){
|
||||
_classname = "ClassFlowMQTT";
|
||||
}
|
||||
// std::string zw = "Classname: " + _classname + "\n";
|
||||
// printf(zw.c_str());
|
||||
|
||||
for (int i = 0; i < FlowControll.size(); ++i)
|
||||
if (FlowControll[i]->name().compare(_classname) == 0){
|
||||
// printf(FlowControll[i]->name().c_str()); printf("\n");
|
||||
FlowControll[i]->doFlow("");
|
||||
FlowControll[i]->doFlow("");
|
||||
result = FlowControll[i]->getHTMLSingleStep(_host);
|
||||
}
|
||||
|
||||
@@ -76,6 +75,8 @@ void ClassFlowControll::SetInitialParameter(void)
|
||||
flowdigit = NULL;
|
||||
flowanalog = NULL;
|
||||
flowpostprocessing = NULL;
|
||||
disabled = false;
|
||||
|
||||
}
|
||||
|
||||
bool ClassFlowControll::isAutoStart(long &_intervall)
|
||||
@@ -356,9 +357,17 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
{
|
||||
string zw = "Set TimeZone: " + zerlegt[1];
|
||||
reset_servername(zerlegt[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "HOSTNAME") && (zerlegt.size() > 1))
|
||||
{
|
||||
if (ChangeHostName("/sdcard/wlan.ini", zerlegt[1]))
|
||||
{
|
||||
// reboot notwendig damit die neue wlan.ini auch benutzt wird !!!
|
||||
fclose(pfile);
|
||||
doReboot();
|
||||
}
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "SETUPMODE") && (zerlegt.size() > 1))
|
||||
{
|
||||
@@ -367,9 +376,6 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
SetupModeActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ void ClassFlowDigit::SetInitialParameter(void)
|
||||
ListFlowControll = NULL;
|
||||
previousElement = NULL;
|
||||
SaveAllFiles = false;
|
||||
disabled = false;
|
||||
|
||||
}
|
||||
|
||||
ClassFlowDigit::ClassFlowDigit() : ClassFlowImage(TAG)
|
||||
@@ -87,10 +89,10 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
return false;
|
||||
|
||||
|
||||
if (aktparamgraph.compare("[Digits]") != 0) // Paragraph passt nich zu MakeImage
|
||||
if (aktparamgraph.compare("[Digits]") != 0) // Paragraph passt nicht
|
||||
return false;
|
||||
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||
while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph))
|
||||
{
|
||||
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
||||
if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1))
|
||||
|
||||
@@ -11,18 +11,22 @@ ClassFlowImage::ClassFlowImage(const char* logTag)
|
||||
{
|
||||
this->logTag = logTag;
|
||||
isLogImage = false;
|
||||
disabled = false;
|
||||
|
||||
}
|
||||
|
||||
ClassFlowImage::ClassFlowImage(std::vector<ClassFlow*> * lfc, const char* logTag) : ClassFlow(lfc)
|
||||
{
|
||||
this->logTag = logTag;
|
||||
isLogImage = false;
|
||||
disabled = false;
|
||||
}
|
||||
|
||||
ClassFlowImage::ClassFlowImage(std::vector<ClassFlow*> * lfc, ClassFlow *_prev, const char* logTag) : ClassFlow(lfc, _prev)
|
||||
{
|
||||
this->logTag = logTag;
|
||||
isLogImage = false;
|
||||
disabled = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ void ClassFlowMQTT::SetInitialParameter(void)
|
||||
user = "";
|
||||
password = "";
|
||||
previousElement = NULL;
|
||||
ListFlowControll = NULL;
|
||||
ListFlowControll = NULL;
|
||||
disabled = false;
|
||||
|
||||
}
|
||||
|
||||
ClassFlowMQTT::ClassFlowMQTT()
|
||||
|
||||
@@ -33,6 +33,7 @@ void ClassFlowMakeImage::SetInitialParameter(void)
|
||||
rawImage = NULL;
|
||||
ImageSize = FRAMESIZE_VGA;
|
||||
SaveAllFiles = false;
|
||||
disabled = false;
|
||||
namerawimage = "/sdcard/img_tmp/raw.jpg";
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ void ClassFlowPostProcessing::SavePreValue(float value, string zwtime)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
ClassFlowPostProcessing::ClassFlowPostProcessing()
|
||||
{
|
||||
PreValueUse = false;
|
||||
@@ -133,8 +133,13 @@ ClassFlowPostProcessing::ClassFlowPostProcessing()
|
||||
checkDigitIncreaseConsistency = false;
|
||||
DecimalShift = 0;
|
||||
ErrorMessageText = "";
|
||||
disabled = false;
|
||||
disabled = false;
|
||||
|
||||
|
||||
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
||||
}
|
||||
*/
|
||||
|
||||
ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ protected:
|
||||
string RundeOutput(float _in, int _anzNachkomma);
|
||||
|
||||
public:
|
||||
ClassFlowPostProcessing();
|
||||
// ClassFlowPostProcessing();
|
||||
ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc);
|
||||
bool ReadParameter(FILE* pfile, string& aktparamgraph);
|
||||
bool doFlow(string time);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CAlignAndCutImage.h"
|
||||
#include "CRotateImage.h"
|
||||
#include "CFindTemplate.h"
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
@@ -33,31 +33,33 @@ void CAlignAndCutImage::GetRefSize(int *ref_dx, int *ref_dy)
|
||||
ref_dy[1] = t1_dy;
|
||||
}
|
||||
|
||||
void CAlignAndCutImage::Align(std::string _template0, int ref0_x, int ref0_y, std::string _template1, int ref1_x, int ref1_y, int deltax, int deltay, std::string imageROI)
|
||||
bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2)
|
||||
{
|
||||
int dx, dy;
|
||||
int r0_x, r0_y, r1_x, r1_y;
|
||||
bool isSimilar1, isSimilar2;
|
||||
|
||||
// CFindTemplate* ft = new CFindTemplate(filename);
|
||||
CFindTemplate* ft = new CFindTemplate(rgb_image, channels, width, height, bpp);
|
||||
|
||||
r0_x = ref0_x;
|
||||
r0_y = ref0_y;
|
||||
ft->FindTemplate(_template0, &r0_x, &r0_y, deltax, deltay);
|
||||
t0_dx = ft->tpl_width;
|
||||
t0_dy = ft->tpl_height;
|
||||
r0_x = _temp1->target_x;
|
||||
r0_y = _temp1->target_y;
|
||||
printf("Vor ft->FindTemplate(_temp1); %s\n", _temp1->image_file.c_str());
|
||||
isSimilar1 = ft->FindTemplate(_temp1);
|
||||
_temp1->width = ft->tpl_width;
|
||||
_temp1->height = ft->tpl_height;
|
||||
|
||||
r1_x = ref1_x;
|
||||
r1_y = ref1_y;
|
||||
ft->FindTemplate(_template1, &r1_x, &r1_y, deltax, deltay);
|
||||
t1_dx = ft->tpl_width;
|
||||
t1_dy = ft->tpl_height;
|
||||
r1_x = _temp2->target_x;
|
||||
r1_y = _temp2->target_y;
|
||||
printf("Vor ft->FindTemplate(_temp2); %s\n", _temp2->image_file.c_str());
|
||||
isSimilar2 = ft->FindTemplate(_temp2);
|
||||
_temp2->width = ft->tpl_width;
|
||||
_temp2->height = ft->tpl_height;
|
||||
|
||||
delete ft;
|
||||
|
||||
|
||||
dx = ref0_x - r0_x;
|
||||
dy = ref0_y - r0_y;
|
||||
dx = _temp1->target_x - _temp1->found_x;
|
||||
dy = _temp1->target_y - _temp1->found_y;
|
||||
|
||||
r0_x += dx;
|
||||
r0_y += dy;
|
||||
@@ -67,32 +69,32 @@ void CAlignAndCutImage::Align(std::string _template0, int ref0_x, int ref0_y, st
|
||||
|
||||
float w_org, w_ist, d_winkel;
|
||||
|
||||
w_org = atan2(ref1_y - ref0_y, ref1_x - ref0_x);
|
||||
w_org = atan2(_temp2->found_y - _temp1->found_y, _temp2->found_x - _temp1->found_x);
|
||||
w_ist = atan2(r1_y - r0_y, r1_x - r0_x);
|
||||
|
||||
d_winkel = (w_org - w_ist) * 180 / M_PI;
|
||||
|
||||
if (imageROI.length() > 0)
|
||||
{
|
||||
CImageBasis* imgzw = new CImageBasis(this);
|
||||
imgzw->drawRect(r0_x, r0_y, t0_dx, t0_dy, 255, 0, 0, 2);
|
||||
imgzw->drawRect(r1_x, r1_y, t1_dx, t1_dy, 255, 0, 0, 2);
|
||||
imgzw->SaveToFile(imageROI);
|
||||
printf("Alignment: alignment ROI created: %s\n", imageROI.c_str());
|
||||
delete imgzw;
|
||||
}
|
||||
d_winkel = (w_ist - w_org) * 180 / M_PI;
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
std::string zw = "\tdx:\t" + std::to_string(dx) + "\tdy:\t" + std::to_string(dy) + "\td_winkel:\t" + std::to_string(d_winkel);
|
||||
// LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
|
||||
zw = zw + "\tt1_x_y:\t" + std::to_string(_temp1->found_x) + "\t" + std::to_string(_temp1->found_y);
|
||||
zw = zw + "\tpara1_found_min_avg_max_SAD:\t" + std::to_string(_temp1->fastalg_min) + "\t" + std::to_string(_temp1->fastalg_avg) + "\t" + std::to_string(_temp1->fastalg_max) + "\t"+ std::to_string(_temp1->fastalg_SAD);
|
||||
zw = zw + "\tt2_x_y:\t" + std::to_string(_temp2->found_x) + "\t" + std::to_string(_temp2->found_y);
|
||||
zw = zw + "\tpara2_found_min_avg_max:\t" + std::to_string(_temp2->fastalg_min) + "\t" + std::to_string(_temp2->fastalg_avg) + "\t" + std::to_string(_temp2->fastalg_max) + "\t"+ std::to_string(_temp2->fastalg_SAD);
|
||||
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
|
||||
#endif
|
||||
|
||||
CRotateImage rt(this, ImageTMP);
|
||||
rt.Translate(dx, dy);
|
||||
rt.Rotate(d_winkel, ref0_x, ref0_y);
|
||||
rt.Rotate(d_winkel, _temp1->target_x, _temp1->target_y);
|
||||
printf("Alignment: dx %d - dy %d - rot %f\n", dx, dy, d_winkel);
|
||||
|
||||
return (isSimilar1 && isSimilar2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void CAlignAndCutImage::CutAndSave(std::string _template1, int x1, int y1, int dx, int dy)
|
||||
{
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "CImageBasis.h"
|
||||
#include "CFindTemplate.h"
|
||||
|
||||
|
||||
class CAlignAndCutImage : public CImageBasis
|
||||
{
|
||||
@@ -9,7 +11,8 @@ class CAlignAndCutImage : public CImageBasis
|
||||
CAlignAndCutImage(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) : CImageBasis(_rgb_image, _channels, _width, _height, _bpp) {ImageTMP = NULL;};
|
||||
CAlignAndCutImage(CImageBasis *_org, CImageBasis *_temp);
|
||||
|
||||
void Align(std::string _template1, int x1, int y1, std::string _template2, int x2, int y2, int deltax = 40, int deltay = 40, std::string imageROI = "");
|
||||
bool Align(RefInfo *_temp1, RefInfo *_temp2);
|
||||
// void Align(std::string _template1, int x1, int y1, std::string _template2, int x2, int y2, int deltax = 40, int deltay = 40, std::string imageROI = "");
|
||||
void CutAndSave(std::string _template1, int x1, int y1, int dx, int dy);
|
||||
CImageBasis* CutAndSave(int x1, int y1, int dx, int dy);
|
||||
void CutAndSave(int x1, int y1, int dx, int dy, CImageBasis *_target);
|
||||
|
||||
@@ -1,91 +1,185 @@
|
||||
#include "CFindTemplate.h"
|
||||
|
||||
void CFindTemplate::FindTemplate(std::string _template, int* found_x, int* found_y)
|
||||
{
|
||||
FindTemplate(_template, found_x, found_y, 0, 0);
|
||||
}
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
void CFindTemplate::FindTemplate(std::string _template, int* found_x, int* found_y, int _dx, int _dy)
|
||||
#define DEBUG_DETAIL_ON
|
||||
|
||||
|
||||
bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
{
|
||||
uint8_t* rgb_template = stbi_load(_template.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels);
|
||||
uint8_t* rgb_template = stbi_load(_ref->image_file.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels);
|
||||
|
||||
// printf("FindTemplate 01\n");
|
||||
|
||||
int ow, ow_start, ow_stop;
|
||||
int oh, oh_start, oh_stop;
|
||||
|
||||
if (_dx == 0)
|
||||
if (_ref->search_x == 0)
|
||||
{
|
||||
_dx = width;
|
||||
*found_x = 0;
|
||||
_ref->search_x = width;
|
||||
_ref->found_x = 0;
|
||||
}
|
||||
|
||||
if (_dy == 0)
|
||||
if (_ref->search_y == 0)
|
||||
{
|
||||
_dy = height;
|
||||
*found_y = 0;
|
||||
_ref->search_y = height;
|
||||
_ref->found_y = 0;
|
||||
}
|
||||
|
||||
|
||||
ow_start = *found_x - _dx;
|
||||
ow_start = _ref->target_x - _ref->search_x;
|
||||
ow_start = std::max(ow_start, 0);
|
||||
ow_stop = *found_x + _dx;
|
||||
ow_stop = _ref->target_x + _ref->search_x;
|
||||
if ((ow_stop + tpl_width) > width)
|
||||
ow_stop = width - tpl_width;
|
||||
ow = ow_stop - ow_start + 1;
|
||||
|
||||
oh_start = *found_y - _dy;
|
||||
oh_start = _ref->target_y - _ref->search_y;
|
||||
oh_start = std::max(oh_start, 0);
|
||||
oh_stop = *found_y + _dy;
|
||||
oh_stop = _ref->target_y + _ref->search_y;
|
||||
if ((oh_stop + tpl_height) > height)
|
||||
oh_stop = height - tpl_height;
|
||||
oh = oh_stop - oh_start + 1;
|
||||
|
||||
uint8_t* odata = (unsigned char*)GET_MEMORY(ow * oh * channels);
|
||||
float avg, SAD;
|
||||
int min, max;
|
||||
bool isSimilar = false;
|
||||
|
||||
// printf("FindTemplate 02\n");
|
||||
|
||||
if ((_ref->alignment_algo == 2) && (_ref->fastalg_x > -1) && (_ref->fastalg_y > -1)) // für Testzwecke immer Berechnen
|
||||
{
|
||||
isSimilar = CalculateSimularities(rgb_template, _ref->fastalg_x, _ref->fastalg_y, ow, oh, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria);
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
std::string zw = "\t" + _ref->image_file + "\tt1_x_y:\t" + std::to_string(_ref->fastalg_x) + "\t" + std::to_string(_ref->fastalg_y);
|
||||
zw = zw + "\tpara1_found_min_avg_max_SAD:\t" + std::to_string(min) + "\t" + std::to_string(avg) + "\t" + std::to_string(max) + "\t"+ std::to_string(SAD);
|
||||
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
|
||||
#endif
|
||||
}
|
||||
|
||||
// printf("FindTemplate 03\n");
|
||||
|
||||
|
||||
if (isSimilar)
|
||||
{
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteToFile("Use FastAlignment sucessfull");
|
||||
#endif
|
||||
_ref->found_x = _ref->fastalg_x;
|
||||
_ref->found_y = _ref->fastalg_y;
|
||||
return true;
|
||||
}
|
||||
|
||||
// printf("FindTemplate 04\n");
|
||||
|
||||
|
||||
double aktSAD;
|
||||
double minSAD = pow(tpl_width * tpl_height * 255, 2);
|
||||
|
||||
RGBImageLock();
|
||||
|
||||
for (int xouter = ow_start; xouter <= ow_stop; xouter++)
|
||||
for (int youter = oh_start; youter <= oh_stop; ++youter)
|
||||
// printf("FindTemplate 05\n");
|
||||
int xouter, youter, tpl_x, tpl_y, _ch;
|
||||
int _anzchannels = channels;
|
||||
if (_ref->alignment_algo == 0) // 0 = "Default" (nur R-Kanal)
|
||||
_anzchannels = 1;
|
||||
|
||||
for (xouter = ow_start; xouter <= ow_stop; xouter++)
|
||||
for (youter = oh_start; youter <= oh_stop; ++youter)
|
||||
{
|
||||
aktSAD = 0;
|
||||
for (int tpl_x = 0; tpl_x < tpl_width; tpl_x++)
|
||||
for (int tpl_y = 0; tpl_y < tpl_height; tpl_y++)
|
||||
for (tpl_x = 0; tpl_x < tpl_width; tpl_x++)
|
||||
for (tpl_y = 0; tpl_y < tpl_height; tpl_y++)
|
||||
{
|
||||
stbi_uc* p_org = rgb_image + (channels * ((youter + tpl_y) * width + (xouter + tpl_x)));
|
||||
stbi_uc* p_tpl = rgb_template + (channels * (tpl_y * tpl_width + tpl_x));
|
||||
aktSAD += pow(p_tpl[0] - p_org[0], 2);
|
||||
for (_ch = 0; _ch < _anzchannels; ++_ch)
|
||||
{
|
||||
aktSAD += pow(p_tpl[_ch] - p_org[_ch], 2);
|
||||
}
|
||||
}
|
||||
stbi_uc* p_out = odata + (channels * ((youter - oh_start) * ow + (xouter - ow_start)));
|
||||
|
||||
p_out[0] = int(sqrt(aktSAD / (tpl_width * tpl_height)));
|
||||
if (aktSAD < minSAD)
|
||||
{
|
||||
minSAD = aktSAD;
|
||||
*found_x = xouter;
|
||||
*found_y = youter;
|
||||
_ref->found_x = xouter;
|
||||
_ref->found_y = youter;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("FindTemplate 06\n");
|
||||
|
||||
|
||||
if (_ref->alignment_algo == 2)
|
||||
CalculateSimularities(rgb_template, _ref->found_x, _ref->found_y, ow, oh, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria);
|
||||
|
||||
|
||||
// printf("FindTemplate 07\n");
|
||||
|
||||
_ref->fastalg_x = _ref->found_x;
|
||||
_ref->fastalg_y = _ref->found_y;
|
||||
_ref->fastalg_min = min;
|
||||
_ref->fastalg_avg = avg;
|
||||
_ref->fastalg_max = max;
|
||||
_ref->fastalg_SAD = SAD;
|
||||
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
std::string zw = "\t" + _ref->image_file + "\tt1_x_y:\t" + std::to_string(_ref->fastalg_x) + "\t" + std::to_string(_ref->fastalg_y);
|
||||
zw = zw + "\tpara1_found_min_avg_max_SAD:\t" + std::to_string(min) + "\t" + std::to_string(avg) + "\t" + std::to_string(max) + "\t"+ std::to_string(SAD);
|
||||
LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", zw);
|
||||
#endif
|
||||
|
||||
RGBImageRelease();
|
||||
|
||||
stbi_write_bmp("sdcard\\find.bmp", ow, oh, channels, odata);
|
||||
|
||||
stbi_image_free(odata);
|
||||
stbi_image_free(rgb_template);
|
||||
|
||||
// printf("FindTemplate 08\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CFindTemplate::FindTemplate(std::string _template, int* found_x, int* found_y, std::string _imageout)
|
||||
|
||||
|
||||
bool CFindTemplate::CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _starty, int _sizex, int _sizey, int &min, float &avg, int &max, float &SAD, float _SADold, float _SADcrit)
|
||||
{
|
||||
FindTemplate(_template, found_x, found_y);
|
||||
SaveToFile(_imageout);
|
||||
}
|
||||
int dif;
|
||||
int minDif = 255;
|
||||
int maxDif = -255;
|
||||
double avgDifSum = 0;
|
||||
long int anz = 0;
|
||||
double aktSAD = 0;
|
||||
|
||||
void CFindTemplate::FindTemplate(std::string _template, int* found_x, int* found_y, int _dx, int _dy, std::string _imageout)
|
||||
{
|
||||
FindTemplate(_template, found_x, found_y, _dx, _dy);
|
||||
SaveToFile(_imageout);
|
||||
int xouter, youter, _ch;
|
||||
|
||||
for (xouter = 0; xouter <= _sizex; xouter++)
|
||||
for (youter = 0; youter <= _sizey; ++youter)
|
||||
{
|
||||
stbi_uc* p_org = rgb_image + (channels * ((youter + _starty) * width + (xouter + _startx)));
|
||||
stbi_uc* p_tpl = _rgb_tmpl + (channels * (youter * tpl_width + xouter));
|
||||
for (_ch = 0; _ch < channels; ++_ch)
|
||||
{
|
||||
dif = p_tpl[_ch] - p_org[_ch];
|
||||
aktSAD += pow(p_tpl[_ch] - p_org[_ch], 2);
|
||||
if (dif < minDif) minDif = dif;
|
||||
if (dif > maxDif) maxDif = dif;
|
||||
avgDifSum += dif;
|
||||
anz++;
|
||||
}
|
||||
}
|
||||
|
||||
avg = avgDifSum / anz;
|
||||
min = minDif;
|
||||
max = maxDif;
|
||||
SAD = sqrt(aktSAD) / anz;
|
||||
|
||||
float _SADdif = abs(SAD - _SADold);
|
||||
|
||||
printf("Anzahl %ld, avgDifSum %fd, avg %f, SAD_neu: %fd, _SAD_old: %f, _SAD_crit:%f\n", anz, avgDifSum, avg, SAD, _SADold, _SADdif);
|
||||
|
||||
if (_SADdif <= _SADcrit)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,40 @@
|
||||
#ifndef __CFINDTEMPLATE_CLASS
|
||||
#define __CFINDTEMPLATE_CLASS
|
||||
|
||||
#include "CImageBasis.h"
|
||||
|
||||
struct RefInfo {
|
||||
std::string image_file;
|
||||
int target_x = 0;
|
||||
int target_y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int found_x;
|
||||
int found_y;
|
||||
int search_x;
|
||||
int search_y;
|
||||
int fastalg_x = -1;
|
||||
int fastalg_y = -1;
|
||||
int fastalg_min = -256;
|
||||
float fastalg_avg = -1;
|
||||
int fastalg_max = -1;
|
||||
float fastalg_SAD = -1;
|
||||
float fastalg_SAD_criteria = -1;
|
||||
int alignment_algo = 0; // 0 = "Default" (nur R-Kanal), 1 = "HighAccurity" (RGB-Kanal), 2 = "Fast" (1.x RGB, dann isSimilar)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class CFindTemplate : public CImageBasis
|
||||
{
|
||||
public:
|
||||
int tpl_width, tpl_height, tpl_bpp;
|
||||
// CFindTemplate(std::string _image);
|
||||
CFindTemplate(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) : CImageBasis(_rgb_image, _channels, _width, _height, _bpp) {};
|
||||
|
||||
bool FindTemplate(RefInfo *_ref);
|
||||
|
||||
void FindTemplate(std::string _template, int* found_x, int* found_y, std::string _imageout);
|
||||
void FindTemplate(std::string _template, int* found_x, int* found_y, int _dx, int _dy, std::string _imageout);
|
||||
void FindTemplate(std::string _template, int* found_x, int* found_y);
|
||||
void FindTemplate(std::string _template, int* found_x, int* found_y, int _dx, int _dy);
|
||||
};
|
||||
bool CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _starty, int _sizex, int _sizey, int &min, float &avg, int &max, float &SAD, float _SADold, float _SADcrit);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user