blob: ac35114305e07a2fd5df1564b8a6dcd3fbd70896 [file] [log] [blame]
Austin Schuh4e2629d2019-03-28 14:44:37 -07001#include <fstream>
2#include <sys/stat.h>
3
4#include "aos/logging/logging.h"
5#include "y2019/vision/image_writer.h"
6
7namespace y2019 {
8namespace vision {
9
10ImageWriter::ImageWriter() {
11 LOG(INFO, "Initializing image writer\n");
12 SetDirPath();
13}
14
15void ImageWriter::WriteImage(::aos::vision::DataRef data) {
16 LOG(INFO, "Writing image %d", image_count_);
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
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 + "/";
32 LOG(INFO, "Writing to %s\n", file_prefix_.c_str());
33 mkdir(file_prefix_.c_str(), 0777);
34 break;
35 }
36 }
37}
38
39} // namespace vision
40} // namespace y2019