From f9326023dc75fbc911e5f1afc1f57110962b212a Mon Sep 17 00:00:00 2001 From: sz Date: Sat, 4 Feb 2023 21:06:13 -0600 Subject: [PATCH] Special case for running the "ALL" check (9-way compare) on seed locations The idea being that we might be 1px off in both dimensions (frankly, it might be worse than that...), and that it doesn't do us any harm to run the extra checks in this one instance. Probably --- src/lib/cimb_translator/CellDrift.cpp | 7 +++++-- src/lib/cimb_translator/CimbDecoder.cpp | 5 +++-- src/lib/cimb_translator/CimbDecoder.h | 6 +++--- src/lib/cimb_translator/CimbReader.cpp | 2 +- src/lib/cimb_translator/FloodDecodePositions.cpp | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/cimb_translator/CellDrift.cpp b/src/lib/cimb_translator/CellDrift.cpp index 53ffd319..ab78faed 100644 --- a/src/lib/cimb_translator/CellDrift.cpp +++ b/src/lib/cimb_translator/CellDrift.cpp @@ -33,14 +33,17 @@ void CellDrift::updateDrift(int dx, int dy) // static uint8_t CellDrift::calculate_cooldown(uint8_t previous, uint8_t idx) { - // previous xor idx == 6?? + if (idx % 2 == 0) + return 0xFF; + // if idx % 2 == 1 and previous xor idx == 6 + // return 0xFF; // ? if (previous == 1 and idx == 7) return 0xFF; if (previous == 3 and idx == 5) return 0xFF; if (previous == 5 and idx == 3) return 0xFF; - if (previous == 1 and idx == 7) + if (previous == 7 and idx == 1) return 0xFF; return idx; } diff --git a/src/lib/cimb_translator/CimbDecoder.cpp b/src/lib/cimb_translator/CimbDecoder.cpp index b77bd373..f4e16725 100644 --- a/src/lib/cimb_translator/CimbDecoder.cpp +++ b/src/lib/cimb_translator/CimbDecoder.cpp @@ -115,12 +115,13 @@ unsigned CimbDecoder::get_best_symbol(image_hash::ahash_result& results, unsigne unsigned CimbDecoder::decode_symbol(const cv::Mat& cell, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown) const { image_hash::ahash_result results = image_hash::fuzzy_ahash(cell, _ahashThreshold, image_hash::ahash_result::FAST); - return get_best_symbol(results, drift_offset, best_distance); + return get_best_symbol(results, drift_offset, best_distance, cooldown); } unsigned CimbDecoder::decode_symbol(const bitmatrix& cell, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown) const { - image_hash::ahash_result results = image_hash::fuzzy_ahash(cell, image_hash::ahash_result::FAST); + int checkRule = cooldown == 0xFE? image_hash::ahash_result::ALL : image_hash::ahash_result::FAST; + image_hash::ahash_result results = image_hash::fuzzy_ahash(cell, checkRule); return get_best_symbol(results, drift_offset, best_distance, cooldown); } diff --git a/src/lib/cimb_translator/CimbDecoder.h b/src/lib/cimb_translator/CimbDecoder.h index 4b3262ed..7ff652c2 100644 --- a/src/lib/cimb_translator/CimbDecoder.h +++ b/src/lib/cimb_translator/CimbDecoder.h @@ -16,9 +16,9 @@ class CimbDecoder void update_color_correction(cv::Matx&& ccm); - unsigned get_best_symbol(image_hash::ahash_result& results, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown=~0U) const; - unsigned decode_symbol(const cv::Mat& cell, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown=~0U) const; - unsigned decode_symbol(const bitmatrix& cell, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown=~0U) const; + unsigned get_best_symbol(image_hash::ahash_result& results, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown=0xFF) const; + unsigned decode_symbol(const cv::Mat& cell, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown=0xFF) const; + unsigned decode_symbol(const bitmatrix& cell, unsigned& drift_offset, unsigned& best_distance, unsigned cooldown=0xFF) const; unsigned get_best_color(float r, float g, float b) const; unsigned decode_color(const Cell& cell) const; diff --git a/src/lib/cimb_translator/CimbReader.cpp b/src/lib/cimb_translator/CimbReader.cpp index 37e8c857..78e95446 100644 --- a/src/lib/cimb_translator/CimbReader.cpp +++ b/src/lib/cimb_translator/CimbReader.cpp @@ -29,7 +29,7 @@ namespace { { // will this need to change for smaller tiles? probably? - int blockSize = 7; // default: no preprocessing + int blockSize = 5; // default: no preprocessing cv::Mat symbols; cv::cvtColor(img, symbols, cv::COLOR_RGB2GRAY); diff --git a/src/lib/cimb_translator/FloodDecodePositions.cpp b/src/lib/cimb_translator/FloodDecodePositions.cpp index c0e8c7e5..1490e757 100644 --- a/src/lib/cimb_translator/FloodDecodePositions.cpp +++ b/src/lib/cimb_translator/FloodDecodePositions.cpp @@ -21,7 +21,7 @@ void FloodDecodePositions::reset() for (unsigned i = 0; i < _positions.size(); ++i) { _remaining.push_back(true); - _instructions.push_back({CellDrift(), 0xFF, 0xFF}); + _instructions.push_back({CellDrift(), 0xFE, 0xFE}); } // seed