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