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