blob: ee65cfe50bc893c9dec1407eaa78142b622a8d39 [file] [log] [blame]
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -08001#include "aos/events/shm_event_loop.h"
2#include "aos/init.h"
3#include "y2020/vision/camera_reader.h"
4
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
25 const auto index_params = cv::makePtr<cv::flann::IndexParams>();
26 index_params->setAlgorithm(cvflann::FLANN_INDEX_KDTREE);
27 index_params->setInt("trees", 5);
28 const auto search_params =
29 cv::makePtr<cv::flann::SearchParams>(/* checks */ 50);
30 cv::FlannBasedMatcher matcher(index_params, search_params);
31
32 aos::ShmEventLoop event_loop(&config.message());
33
34 // First, log the data for future reference.
35 {
36 aos::Sender<sift::TrainingData> training_data_sender =
37 event_loop.MakeSender<sift::TrainingData>("/camera");
38 CHECK_EQ(training_data_sender.Send(training_data),
39 aos::RawSender::Error::kOk);
40 }
41
42 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
43 CameraReader camera_reader(&event_loop, &training_data.message(),
44 &v4l2_reader, index_params, search_params);
45
46 v4l2_reader.SetExposure(FLAGS_exposure);
47
48 event_loop.Run();
49}
50
51} // namespace
52} // namespace vision
53} // namespace y2022
54
55int main(int argc, char **argv) {
56 aos::InitGoogle(&argc, &argv);
57 y2022::vision::CameraReaderMain();
58}