Brian Silverman | 9dd793b | 2020-01-31 23:52:21 -0800 | [diff] [blame^] | 1 | #include "aos/events/shm_event_loop.h" |
| 2 | #include "aos/init.h" |
| 3 | |
| 4 | #include "y2020/vision/v4l2_reader.h" |
| 5 | |
| 6 | namespace frc971 { |
| 7 | namespace vision { |
| 8 | namespace { |
| 9 | |
| 10 | void CameraReaderMain() { |
| 11 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 12 | aos::configuration::ReadConfig("config.json"); |
| 13 | |
| 14 | aos::ShmEventLoop event_loop(&config.message()); |
| 15 | V4L2Reader v4l2_reader(&event_loop, "/dev/video0"); |
| 16 | |
| 17 | while (true) { |
| 18 | const auto image = v4l2_reader.ReadLatestImage(); |
| 19 | if (image.empty()) { |
| 20 | LOG(INFO) << "No image, sleeping"; |
| 21 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 22 | continue; |
| 23 | } |
| 24 | |
| 25 | // Now, process image. |
| 26 | // TODO(Brian): Actually process it, rather than just logging its size... |
| 27 | LOG(INFO) << image.size(); |
| 28 | std::this_thread::sleep_for(std::chrono::milliseconds(70)); |
| 29 | |
| 30 | v4l2_reader.SendLatestImage(); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | } // namespace |
| 35 | } // namespace vision |
| 36 | } // namespace frc971 |
| 37 | |
| 38 | |
| 39 | int main(int argc, char **argv) { |
| 40 | aos::InitGoogle(&argc, &argv); |
| 41 | frc971::vision::CameraReaderMain(); |
| 42 | } |