|
@@ -62,15 +62,15 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
|
|
oh_stop = height - tpl_height;
|
|
oh_stop = height - tpl_height;
|
|
|
oh = oh_stop - oh_start + 1;
|
|
oh = oh_stop - oh_start + 1;
|
|
|
|
|
|
|
|
- float avg, SAD;
|
|
|
|
|
- int min, max;
|
|
|
|
|
|
|
+ float avg = 0, SAD = 0;
|
|
|
|
|
+ int min = 0, max = 0;
|
|
|
bool isSimilar = false;
|
|
bool isSimilar = false;
|
|
|
|
|
|
|
|
// ESP_LOGD(TAG, "FindTemplate 02");
|
|
// ESP_LOGD(TAG, "FindTemplate 02");
|
|
|
|
|
|
|
|
if ((_ref->alignment_algo == 2) && (_ref->fastalg_x > -1) && (_ref->fastalg_y > -1)) // für Testzwecke immer Berechnen
|
|
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);
|
|
|
|
|
|
|
+ isSimilar = CalculateSimularities(rgb_template, _ref->fastalg_x, _ref->fastalg_y, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria);
|
|
|
/*#ifdef DEBUG_DETAIL_ON
|
|
/*#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);
|
|
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);
|
|
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);
|
|
@@ -146,7 +146,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_ref->alignment_algo == 2)
|
|
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);
|
|
|
|
|
|
|
+ CalculateSimularities(rgb_template, _ref->found_x, _ref->found_y, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria);
|
|
|
|
|
|
|
|
|
|
|
|
|
// ESP_LOGD(TAG, "FindTemplate 07");
|
|
// ESP_LOGD(TAG, "FindTemplate 07");
|
|
@@ -175,7 +175,9 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-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)
|
|
|
|
|
|
|
+// Compares the template with the image at (_startx, _starty) and reports whether the match is still as
|
|
|
|
|
+// good as the stored one. Used by the "Fast" alignment to skip the full search.
|
|
|
|
|
+bool CFindTemplate::CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _starty, int &min, float &avg, int &max, float &SAD, float _SADold, float _SADcrit)
|
|
|
{
|
|
{
|
|
|
int dif;
|
|
int dif;
|
|
|
int minDif = 255;
|
|
int minDif = 255;
|
|
@@ -186,8 +188,15 @@ bool CFindTemplate::CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _
|
|
|
|
|
|
|
|
int xouter, youter, _ch;
|
|
int xouter, youter, _ch;
|
|
|
|
|
|
|
|
- for (xouter = 0; xouter <= _sizex; xouter++)
|
|
|
|
|
- for (youter = 0; youter <= _sizey; ++youter)
|
|
|
|
|
|
|
+ // The template has to lie completely inside the image at this position. The stored position comes
|
|
|
|
|
+ // from /config/align.txt and may belong to an older reference image.
|
|
|
|
|
+ if ((_startx < 0) || (_starty < 0) || ((_startx + tpl_width) > width) || ((_starty + tpl_height) > height))
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ // Walk the template, not the search area: the former loop ran over the search area size (plus one)
|
|
|
|
|
+ // and so read past the end of the template buffer and compared pixels that are not part of the marker.
|
|
|
|
|
+ for (xouter = 0; xouter < tpl_width; xouter++)
|
|
|
|
|
+ for (youter = 0; youter < tpl_height; ++youter)
|
|
|
{
|
|
{
|
|
|
stbi_uc* p_org = rgb_image + (channels * ((youter + _starty) * width + (xouter + _startx)));
|
|
stbi_uc* p_org = rgb_image + (channels * ((youter + _starty) * width + (xouter + _startx)));
|
|
|
stbi_uc* p_tpl = _rgb_tmpl + (channels * (youter * tpl_width + xouter));
|
|
stbi_uc* p_tpl = _rgb_tmpl + (channels * (youter * tpl_width + xouter));
|