From: Skullheadx Date: Wed, 27 Nov 2024 03:30:06 +0000 (-0500) Subject: find col coordinates for finder patterns X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.js?a=commitdiff_plain;h=34eae4230d08712b3cd445a41f6aee0b855db987;p=qrcodescanner.git find col coordinates for finder patterns --- diff --git a/.DS_Store b/.DS_Store index 36f964d..27a8c8a 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/camera.cpp b/camera.cpp index 6740f27..453f7c1 100644 --- a/camera.cpp +++ b/camera.cpp @@ -3,6 +3,7 @@ #include #include + void print(std::vector &vec); void print(std::vector> &symbol); void print(std::vector> &grid); @@ -16,6 +17,7 @@ void retrieve_codewords(std::vector> &symbol, std::vector> &symbol, std::vector &codewords, bool is_upwards, int row, int col); void apply_global_threshold(std::vector> &grid, std::vector> &symbol); +std::vector> get_finder_coords(std::vector> &symbol); std::vector get_format_info(std::vector> &symbol); void decode_mask(std::vector> &symbol, std::size_t mask_pattern); std::vector get_codewords_from_symbol(std::vector> &symbol); @@ -23,26 +25,66 @@ std::string get_input_data(std::vector &input_data, unsigned int character std::string decode_symbol(std::vector> &symbol); int main(){ - //std::vector test_cases = {"012345678", "876543210", "000000000", "999999999", "123456789", "873703846", "884158624", "827515735", "869871935", "804235824"}; - std::vector test_cases = {"6969696969"}; - - std::vector> camera_input(8, std::vector(6,0)); + std::vector> camera_input(32, std::vector(24,0)); // 800 x 600 unsigned int counter{0}; for (auto &r : camera_input){ for (auto &col:r){ - col = 255 * (counter / 8.0); + col = 255 * (counter / 32.0); } counter++; } + camera_input[0][0] = 255; + camera_input[0][1] = 0; + camera_input[0][2] = 255; + camera_input[0][3] = 255; + camera_input[0][4] = 255; + camera_input[0][5] = 0; + camera_input[0][6] = 255; + camera_input[0][7] = 0; + + camera_input[0][8] = 255; + camera_input[0][9] = 0; + camera_input[0][10] = 255; + camera_input[0][11] = 255; + camera_input[0][12] = 255; + camera_input[0][13] = 0; + camera_input[0][14] = 255; + + camera_input[1][0] = 255; + camera_input[1][1] = 0; + camera_input[1][2] = 255; + camera_input[1][3] = 255; + camera_input[1][4] = 255; + camera_input[1][5] = 0; + camera_input[1][6] = 255; + camera_input[1][7] = 0; + + camera_input[1][8] = 255; + camera_input[1][9] = 0; + camera_input[1][10] = 255; + camera_input[1][11] = 255; + camera_input[1][12] = 255; + camera_input[1][13] = 0; + camera_input[1][14] = 255; + + camera_input[5][0] = 255; + camera_input[5][1] = 0; + camera_input[5][2] = 255; + camera_input[5][3] = 255; + camera_input[5][4] = 255; + camera_input[5][5] = 0; + camera_input[5][6] = 255; + camera_input[5][7] = 0; + //print(camera_input); - std::vector> symbol_noisy(8, std::vector(6,0)); + std::vector> symbol_noisy(32, std::vector(24,0)); apply_global_threshold(camera_input, symbol_noisy); print(symbol_noisy); - std::vector> symbol(21, std::vector(21,0)); - - + + get_finder_coords(symbol_noisy); + std::vector> symbol(21, std::vector(21,0)); return 0; } @@ -137,8 +179,69 @@ void apply_global_threshold(std::vector> &grid, std::v } } } +int gcd(int a, int b) { + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; +} +bool contains_ratio(std::vector subvec){ + int divisor = gcd(gcd(gcd(gcd(subvec[0], subvec[1]), subvec[2]), subvec[3]), subvec[4]); + std::vector vec = subvec; + for (auto &i: vec){ + i /= divisor; + } + //std::cout << "check ratio: "; for (auto i:vec){std::cout << i << " ";}std::cout << std::endl; + if ((vec[0] > 0.5 && vec[0] < 1.5) && (vec[1] > 0.5 && vec[1] < 1.5) && (vec[3] > 0.5 && vec[3] < 1.5) && (vec[4] > 0.5 && vec[4] < 1.5) && (vec[2] > 2.5 && vec[2] < 3.5)){ + return true; + } + return false; +} +std::vector get_finder_pattern_coords(std::vector &row){ + std::vector values{}; + for (std::size_t i{0}; i < row.size(); ++i){ + if (values.size() == 0){ + values.push_back(1); + } + else if (row[i] == row[i-1]){ + values[values.size() - 1]++; + } + else { + values.push_back(1); + } + } + //std::cout << "values ";for (auto i:values){std::cout << i << " ";}std::cout << std::endl; + + std::vector coords{}; + if (values.size() < 5){return coords;} + for (std::size_t i{0}; i < values.size() - 5 + 1; ++i){ + std::vector subvec(values.begin() + i, values.begin() + i + 5); + //for (auto i:subvec){std::cout << i << " ";}std::cout << std::endl; + if (contains_ratio(subvec)){ + int x{0}; + for (std::size_t j{0}; j < i; ++j){ + x += values[j]; + } + coords.push_back(x); + } + } + return coords; +} + + +std::vector> get_finder_coords(std::vector> &symbol){ + std::vector> coords(3, std::vector(2,0)); + for (std::size_t row{0}; row < symbol.size(); ++row){ + std::vector c = get_finder_pattern_coords(symbol[row]); + for (auto i : c){std::cout << i << " ";}std::cout < get_format_info(std::vector> &symbol){