blob: 6f65a6d612af41b32f197f992aa0ae4d0c107a28 [file] [log] [blame]
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -08001#include "aos/events/shm_event_loop.h"
2#include "aos/init.h"
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -08003#include "y2022/vision/camera_reader.h"
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -08004
5// config used to allow running camera_reader independently. E.g.,
6// bazel run //y2022/vision:camera_reader -- --config y2022/config.json
7// --override_hostname pi-7971-1 --ignore_timestamps true
8DEFINE_string(config, "config.json", "Path to the config file to use.");
9DEFINE_uint32(exposure, 5, "Exposure time, in 100us increments");
10
11namespace y2022 {
12namespace vision {
13namespace {
14
15using namespace frc971::vision;
16
17void CameraReaderMain() {
18 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
19 aos::configuration::ReadConfig(FLAGS_config);
20
21 const aos::FlatbufferSpan<sift::TrainingData> training_data(
22 SiftTrainingData());
23 CHECK(training_data.Verify());
24
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080025 aos::ShmEventLoop event_loop(&config.message());
26
27 // First, log the data for future reference.
28 {
29 aos::Sender<sift::TrainingData> training_data_sender =
30 event_loop.MakeSender<sift::TrainingData>("/camera");
31 CHECK_EQ(training_data_sender.Send(training_data),
32 aos::RawSender::Error::kOk);
33 }
34
35 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080036 v4l2_reader.SetExposure(FLAGS_exposure);
37
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080038 CameraReader camera_reader(&event_loop, &training_data.message(),
39 &v4l2_reader);
40
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080041 event_loop.Run();
42}
43
44} // namespace
45} // namespace vision
46} // namespace y2022
47
48int main(int argc, char **argv) {
49 aos::InitGoogle(&argc, &argv);
50 y2022::vision::CameraReaderMain();
51}