blob: 51e2c60f217b224243cea8af93a7a0244d1a4187 [file] [log] [blame]
Austin Schuh4e2629d2019-03-28 14:44:37 -07001#include <fstream>
2#include <sys/stat.h>
3
Alex Perry670d5ac2019-04-07 14:20:31 -07004#include "glog/logging.h"
Austin Schuh4e2629d2019-03-28 14:44:37 -07005#include "y2019/vision/image_writer.h"
6
7namespace y2019 {
8namespace vision {
9
10ImageWriter::ImageWriter() {
Alex Perry670d5ac2019-04-07 14:20:31 -070011 LOG(INFO) << "Initializing image writer";
Austin Schuh4e2629d2019-03-28 14:44:37 -070012 SetDirPath();
13}
14
15void ImageWriter::WriteImage(::aos::vision::DataRef data) {
Alex Perry670d5ac2019-04-07 14:20:31 -070016 LOG(INFO) << "Writing image " << image_count_;
Austin Schuh4e2629d2019-03-28 14:44:37 -070017 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
25void 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 Perry670d5ac2019-04-07 14:20:31 -070032 LOG(INFO) << "Writing to " << file_prefix_.c_str();
Austin Schuh4e2629d2019-03-28 14:44:37 -070033 mkdir(file_prefix_.c_str(), 0777);
34 break;
35 }
36 }
37}
38
39} // namespace vision
40} // namespace y2019