mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2026-02-03 00:00:48 +03:00
.
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "c_align_and_cut_image";
|
||||
|
||||
//#define GET_MEMORY malloc
|
||||
#define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
|
||||
@@ -43,14 +46,14 @@ bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2)
|
||||
|
||||
r0_x = _temp1->target_x;
|
||||
r0_y = _temp1->target_y;
|
||||
printf("Vor ft->FindTemplate(_temp1); %s\n", _temp1->image_file.c_str());
|
||||
ESP_LOGD(TAG, "Vor ft->FindTemplate(_temp1); %s", _temp1->image_file.c_str());
|
||||
isSimilar1 = ft->FindTemplate(_temp1);
|
||||
_temp1->width = ft->tpl_width;
|
||||
_temp1->height = 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());
|
||||
ESP_LOGD(TAG, "Vor ft->FindTemplate(_temp2); %s", _temp2->image_file.c_str());
|
||||
isSimilar2 = ft->FindTemplate(_temp2);
|
||||
_temp2->width = ft->tpl_width;
|
||||
_temp2->height = ft->tpl_height;
|
||||
@@ -86,7 +89,7 @@ bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2)
|
||||
CRotateImage rt(this, ImageTMP);
|
||||
rt.Translate(dx, dy);
|
||||
rt.Rotate(d_winkel, _temp1->target_x, _temp1->target_y);
|
||||
printf("Alignment: dx %d - dy %d - rot %f\n", dx, dy, d_winkel);
|
||||
ESP_LOGD(TAG, "Alignment: dx %d - dy %d - rot %f", dx, dy, d_winkel);
|
||||
|
||||
return (isSimilar1 && isSimilar2);
|
||||
}
|
||||
@@ -147,7 +150,7 @@ void CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy, CImageBasis *
|
||||
|
||||
if ((_target->height != dy) || (_target->width != dx) || (_target->channels != channels))
|
||||
{
|
||||
printf("CAlignAndCutImage::CutAndSave - Image size does not match !!");
|
||||
ESP_LOGD(TAG, "CAlignAndCutImage::CutAndSave - Image size does not match!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "c_find_template";
|
||||
|
||||
// #define DEBUG_DETAIL_ON
|
||||
|
||||
|
||||
@@ -9,7 +13,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
{
|
||||
uint8_t* rgb_template = stbi_load(_ref->image_file.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels);
|
||||
|
||||
// printf("FindTemplate 01\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 01");
|
||||
|
||||
int ow, ow_start, ow_stop;
|
||||
int oh, oh_start, oh_stop;
|
||||
@@ -45,7 +49,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
int min, max;
|
||||
bool isSimilar = false;
|
||||
|
||||
// printf("FindTemplate 02\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 02");
|
||||
|
||||
if ((_ref->alignment_algo == 2) && (_ref->fastalg_x > -1) && (_ref->fastalg_y > -1)) // für Testzwecke immer Berechnen
|
||||
{
|
||||
@@ -57,7 +61,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
#endif
|
||||
}
|
||||
|
||||
// printf("FindTemplate 03\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 03");
|
||||
|
||||
|
||||
if (isSimilar)
|
||||
@@ -70,7 +74,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
return true;
|
||||
}
|
||||
|
||||
// printf("FindTemplate 04\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 04");
|
||||
|
||||
|
||||
double aktSAD;
|
||||
@@ -78,7 +82,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
|
||||
RGBImageLock();
|
||||
|
||||
// printf("FindTemplate 05\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 05");
|
||||
int xouter, youter, tpl_x, tpl_y, _ch;
|
||||
int _anzchannels = channels;
|
||||
if (_ref->alignment_algo == 0) // 0 = "Default" (nur R-Kanal)
|
||||
@@ -106,14 +110,14 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
}
|
||||
}
|
||||
|
||||
// printf("FindTemplate 06\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 06");
|
||||
|
||||
|
||||
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");
|
||||
// ESP_LOGD(TAG, "FindTemplate 07");
|
||||
|
||||
_ref->fastalg_x = _ref->found_x;
|
||||
_ref->fastalg_y = _ref->found_y;
|
||||
@@ -132,7 +136,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
||||
RGBImageRelease();
|
||||
stbi_image_free(rgb_template);
|
||||
|
||||
// printf("FindTemplate 08\n");
|
||||
// ESP_LOGD(TAG, "FindTemplate 08");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -173,7 +177,7 @@ bool CFindTemplate::CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _
|
||||
|
||||
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);
|
||||
ESP_LOGD(TAG, "Anzahl %ld, avgDifSum %fd, avg %f, SAD_neu: %fd, _SAD_old: %f, _SAD_crit:%f", anz, avgDifSum, avg, SAD, _SADold, _SADdif);
|
||||
|
||||
if (_SADdif <= _SADcrit)
|
||||
return true;
|
||||
|
||||
@@ -61,7 +61,7 @@ uint8_t * CImageBasis::RGBImageGet()
|
||||
|
||||
void writejpghelp(void *context, void *data, int size)
|
||||
{
|
||||
// printf("Size all: %d, size %d\n", ((ImageData*)context)->size, size);
|
||||
// ESP_LOGD(TAG, "Size all: %d, size %d", ((ImageData*)context)->size, size);
|
||||
ImageData* _zw = (ImageData*) context;
|
||||
uint8_t *voidstart = _zw->data;
|
||||
uint8_t *datastart = (uint8_t*) data;
|
||||
@@ -146,7 +146,7 @@ bool CImageBasis::CopyFromMemory(uint8_t* _source, int _size)
|
||||
int gr = height * width * channels;
|
||||
if (gr != _size) // Größe passt nicht
|
||||
{
|
||||
printf("Cannot copy image from memory - sizes do not match: should be %d, but is %d\n", _size, gr);
|
||||
ESP_LOGD(TAG, "Cannot copy image from memory - sizes do not match: should be %d, but is %d", _size, gr);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
|
||||
stbi_image_free(rgb_image);
|
||||
rgb_image = stbi_load_from_memory(_buffer, len, &width, &height, &channels, 3);
|
||||
bpp = channels;
|
||||
printf("Image loaded from memory: %d, %d, %d\n", width, height, channels);
|
||||
ESP_LOGD(TAG, "Image loaded from memory: %d, %d, %d", width, height, channels);
|
||||
if ((width * height * channels) == 0)
|
||||
{
|
||||
ESP_LOGE(TAG, "Image with size 0 loaded --> reboot to be done! "
|
||||
@@ -392,7 +392,7 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat)
|
||||
int anz = 1;
|
||||
while (!rgb_image && (anz < _anzrepeat))
|
||||
{
|
||||
printf("Create Image from Copy - Memory is full - try again: %d.\n", anz);
|
||||
ESP_LOGD(TAG, "Create Image from Copy - Memory is full - try again: %d", anz);
|
||||
rgb_image = (unsigned char*) malloc(memsize);
|
||||
anz++;
|
||||
}
|
||||
@@ -400,8 +400,8 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat)
|
||||
|
||||
if (!rgb_image)
|
||||
{
|
||||
printf(getESPHeapInfo().c_str());
|
||||
printf("\nNo more free memory!! Needed: %d %d %d %d\n", width, height, channels, memsize);
|
||||
ESP_LOGD(TAG, "%s", getESPHeapInfo().c_str());
|
||||
ESP_LOGD(TAG, "No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize);
|
||||
RGBImageRelease();
|
||||
return;
|
||||
}
|
||||
@@ -424,8 +424,8 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels)
|
||||
rgb_image = (unsigned char*)GET_MEMORY(memsize);
|
||||
if (!rgb_image)
|
||||
{
|
||||
printf(getESPHeapInfo().c_str());
|
||||
printf("\nNo more free memory!! Needed: %d %d %d %d\n", width, height, channels, memsize);
|
||||
ESP_LOGD(TAG, "%s", getESPHeapInfo().c_str());
|
||||
ESP_LOGD(TAG, "No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -438,21 +438,21 @@ CImageBasis::CImageBasis(std::string _image)
|
||||
externalImage = false;
|
||||
filename = _image;
|
||||
long zwld = esp_get_free_heap_size();
|
||||
printf("freeheapsize before: %ld\n", zwld);
|
||||
ESP_LOGD(TAG, "freeheapsize before: %ld", zwld);
|
||||
|
||||
RGBImageLock();
|
||||
rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels);
|
||||
RGBImageRelease();
|
||||
|
||||
zwld = esp_get_free_heap_size();
|
||||
printf("freeheapsize after : %ld\n", zwld);
|
||||
ESP_LOGD(TAG, "freeheapsize after : %ld", zwld);
|
||||
|
||||
std::string zw = "Image Load failed:" + _image + "\n";
|
||||
std::string zw = "Image Load failed:" + _image;
|
||||
if (rgb_image == NULL)
|
||||
printf(zw.c_str());
|
||||
ESP_LOGD(TAG, "%s", zw.c_str());
|
||||
zw = "CImageBasis after load " + _image + "\n";
|
||||
printf(zw.c_str());
|
||||
printf("w %d, h %d, b %d, c %d\n", width, height, bpp, channels);
|
||||
ESP_LOGD(TAG, "%s", zw.c_str());
|
||||
ESP_LOGD(TAG, "w %d, h %d, b %d, c %d", width, height, bpp, channels);
|
||||
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ void CImageBasis::Resize(int _new_dx, int _new_dy, CImageBasis *_target)
|
||||
{
|
||||
if ((_target->height != _new_dy) || (_target->width != _new_dx) || (_target->channels != channels))
|
||||
{
|
||||
printf("CImageBasis::Resize - Target image size does not fit !!");
|
||||
ESP_LOGD(TAG, "CImageBasis::Resize - Target image size does not fit!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,13 +280,13 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
|
||||
|
||||
void CRotateImage::Rotate(float _angle)
|
||||
{
|
||||
// printf("width %d, height %d\n", width, height);
|
||||
// ESP_LOGD(TAG, "width %d, height %d", width, height);
|
||||
Rotate(_angle, width / 2, height / 2);
|
||||
}
|
||||
|
||||
void CRotateImage::RotateAntiAliasing(float _angle)
|
||||
{
|
||||
// printf("width %d, height %d\n", width, height);
|
||||
// ESP_LOGD(TAG, "width %d, height %d", width, height);
|
||||
RotateAntiAliasing(_angle, width / 2, height / 2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user