Parker Schuh | 0ff777c | 2017-02-19 15:01:13 -0800 | [diff] [blame] | 1 | #include "aos/vision/blob/test_utils.h" |
| 2 | |
Stephan Pleines | cc500b9 | 2024-05-30 10:58:40 -0700 | [diff] [blame] | 3 | #include <utility> |
| 4 | #include <vector> |
| 5 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 6 | namespace aos::vision { |
Parker Schuh | 0ff777c | 2017-02-19 15:01:13 -0800 | [diff] [blame] | 7 | |
| 8 | RangeImage LoadFromTestData(int mini, const char *data) { |
| 9 | // Consume initial return. |
| 10 | if (*data) ++data; |
| 11 | std::vector<std::vector<ImageRange>> rows; |
| 12 | int x = 0; |
| 13 | bool p_score = false; |
| 14 | int pstart = -1; |
| 15 | std::vector<ImageRange> out_ranges; |
| 16 | |
| 17 | for (; *data; ++data) { |
| 18 | char cell = *data; |
| 19 | |
| 20 | if (cell == '\n') { |
| 21 | if (p_score) { |
| 22 | out_ranges.emplace_back(ImageRange(pstart, x)); |
| 23 | } |
| 24 | rows.emplace_back(out_ranges); |
| 25 | out_ranges = {}; |
| 26 | x = 0; |
| 27 | pstart = -1; |
| 28 | p_score = false; |
| 29 | } else { |
| 30 | if ((cell != ' ') != p_score) { |
| 31 | if (p_score) { |
| 32 | out_ranges.emplace_back(ImageRange(pstart, x)); |
| 33 | } else { |
| 34 | pstart = x; |
| 35 | } |
| 36 | p_score = !p_score; |
| 37 | } |
| 38 | ++x; |
| 39 | } |
| 40 | } |
| 41 | return RangeImage(mini, std::move(rows)); |
| 42 | } |
| 43 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 44 | } // namespace aos::vision |