Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 1 | #include "y2019/vision/image_writer.h" |
| 2 | |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 3 | #include <sys/stat.h> |
| 4 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 5 | #include <fstream> |
| 6 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 7 | #include "absl/log/check.h" |
| 8 | #include "absl/log/log.h" |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 9 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 10 | namespace y2019::vision { |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 11 | |
| 12 | ImageWriter::ImageWriter() { |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 13 | LOG(INFO) << "Initializing image writer"; |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 14 | SetDirPath(); |
| 15 | } |
| 16 | |
| 17 | void ImageWriter::WriteImage(::aos::vision::DataRef data) { |
Alex Perry | 670d5ac | 2019-04-07 14:20:31 -0700 | [diff] [blame] | 18 | LOG(INFO) << "Writing image " << image_count_; |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 19 | std::ofstream ofs( |
| 20 | dir_path_ + file_prefix_ + std::to_string(image_count_) + ".yuyv", |
| 21 | std::ofstream::out); |
| 22 | ofs << data; |
| 23 | ofs.close(); |
| 24 | ++image_count_; |
| 25 | } |
| 26 | |
| 27 | void ImageWriter::SetDirPath() { |
| 28 | ::std::string base_path = "/jevois/data/run_"; |
| 29 | for (int i = 0;; ++i) { |
| 30 | struct stat st; |
| 31 | std::string option = base_path + std::to_string(i); |
| 32 | if (stat(option.c_str(), &st) != 0) { |
| 33 | file_prefix_ = option + "/"; |
Alex Perry | 670d5ac | 2019-04-07 14:20:31 -0700 | [diff] [blame] | 34 | LOG(INFO) << "Writing to " << file_prefix_.c_str(); |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 35 | mkdir(file_prefix_.c_str(), 0777); |
| 36 | break; |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 41 | } // namespace y2019::vision |