blob: 9b73a8100566cc649b183c2e87e92d9cce5c2c94 [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
Alex Perry670d5ac2019-04-07 14:20:31 -07007#include "glog/logging.h"
Austin Schuh4e2629d2019-03-28 14:44:37 -07008
Stephan Pleinesf63bde82024-01-13 15:59:33 -08009namespace y2019::vision {
Austin Schuh4e2629d2019-03-28 14:44:37 -070010
11ImageWriter::ImageWriter() {
Philipp Schrader790cb542023-07-05 21:06:52 -070012 LOG(INFO) << "Initializing image writer";
Austin Schuh4e2629d2019-03-28 14:44:37 -070013 SetDirPath();
14}
15
16void ImageWriter::WriteImage(::aos::vision::DataRef data) {
Alex Perry670d5ac2019-04-07 14:20:31 -070017 LOG(INFO) << "Writing image " << image_count_;
Austin Schuh4e2629d2019-03-28 14:44:37 -070018 std::ofstream ofs(
19 dir_path_ + file_prefix_ + std::to_string(image_count_) + ".yuyv",
20 std::ofstream::out);
21 ofs << data;
22 ofs.close();
23 ++image_count_;
24}
25
26void ImageWriter::SetDirPath() {
27 ::std::string base_path = "/jevois/data/run_";
28 for (int i = 0;; ++i) {
29 struct stat st;
30 std::string option = base_path + std::to_string(i);
31 if (stat(option.c_str(), &st) != 0) {
32 file_prefix_ = option + "/";
Alex Perry670d5ac2019-04-07 14:20:31 -070033 LOG(INFO) << "Writing to " << file_prefix_.c_str();
Austin Schuh4e2629d2019-03-28 14:44:37 -070034 mkdir(file_prefix_.c_str(), 0777);
35 break;
36 }
37 }
38}
39
Stephan Pleinesf63bde82024-01-13 15:59:33 -080040} // namespace y2019::vision