blob: 18b8cae93e2f3bd1f3e4a029216bea1532349153 [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "y2019/vision/image_writer.h"
2
Austin Schuh4e2629d2019-03-28 14:44:37 -07003#include <sys/stat.h>
4
Philipp Schrader790cb542023-07-05 21:06:52 -07005#include <fstream>
6
Austin Schuh99f7c6a2024-06-25 22:07:44 -07007#include "absl/log/check.h"
8#include "absl/log/log.h"
Austin Schuh4e2629d2019-03-28 14:44:37 -07009
Stephan Pleinesf63bde82024-01-13 15:59:33 -080010namespace y2019::vision {
Austin Schuh4e2629d2019-03-28 14:44:37 -070011
12ImageWriter::ImageWriter() {
Philipp Schrader790cb542023-07-05 21:06:52 -070013 LOG(INFO) << "Initializing image writer";
Austin Schuh4e2629d2019-03-28 14:44:37 -070014 SetDirPath();
15}
16
17void ImageWriter::WriteImage(::aos::vision::DataRef data) {
Alex Perry670d5ac2019-04-07 14:20:31 -070018 LOG(INFO) << "Writing image " << image_count_;
Austin Schuh4e2629d2019-03-28 14:44:37 -070019 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
27void 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 Perry670d5ac2019-04-07 14:20:31 -070034 LOG(INFO) << "Writing to " << file_prefix_.c_str();
Austin Schuh4e2629d2019-03-28 14:44:37 -070035 mkdir(file_prefix_.c_str(), 0777);
36 break;
37 }
38 }
39}
40
Stephan Pleinesf63bde82024-01-13 15:59:33 -080041} // namespace y2019::vision