Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 1 | #include "absl/flags/flag.h" |
Yash Maheshwari | 997b331 | 2024-05-18 17:08:44 -0700 | [diff] [blame] | 2 | #include "opencv2/highgui.hpp" |
Maxwell Henderson | 97d0ab2 | 2024-03-16 16:53:10 -0700 | [diff] [blame] | 3 | #include "opencv2/imgproc.hpp" |
Maxwell Henderson | 97d0ab2 | 2024-03-16 16:53:10 -0700 | [diff] [blame] | 4 | |
| 5 | #include "aos/events/logging/log_reader.h" |
| 6 | #include "aos/events/logging/log_writer.h" |
| 7 | #include "aos/events/simulated_event_loop.h" |
| 8 | #include "aos/init.h" |
| 9 | #include "aos/json_to_flatbuffer.h" |
| 10 | #include "aos/logging/log_message_generated.h" |
| 11 | #include "frc971/vision/vision_generated.h" |
| 12 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 13 | ABSL_FLAG(std::string, node, "orin1", "The node to view the log from"); |
| 14 | ABSL_FLAG(std::string, channel, "/camera0", "The channel to view the log from"); |
Maxwell Henderson | 97d0ab2 | 2024-03-16 16:53:10 -0700 | [diff] [blame] | 15 | |
| 16 | int main(int argc, char **argv) { |
| 17 | aos::InitGoogle(&argc, &argv); |
| 18 | |
| 19 | // open logfiles |
| 20 | aos::logger::LogReader reader( |
| 21 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv))); |
| 22 | |
| 23 | aos::SimulatedEventLoopFactory factory(reader.configuration()); |
| 24 | reader.Register(&factory); |
| 25 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 26 | aos::NodeEventLoopFactory *node = |
| 27 | factory.GetNodeEventLoopFactory(absl::GetFlag(FLAGS_node)); |
Maxwell Henderson | 97d0ab2 | 2024-03-16 16:53:10 -0700 | [diff] [blame] | 28 | |
| 29 | std::unique_ptr<aos::EventLoop> image_loop = node->MakeEventLoop("image"); |
| 30 | image_loop->MakeWatcher( |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 31 | "/" + absl::GetFlag(FLAGS_node) + "/" + absl::GetFlag(FLAGS_channel), |
Maxwell Henderson | 97d0ab2 | 2024-03-16 16:53:10 -0700 | [diff] [blame] | 32 | [](const frc971::vision::CameraImage &msg) { |
| 33 | cv::Mat color_image(cv::Size(msg.cols(), msg.rows()), CV_8UC2, |
| 34 | (void *)msg.data()->data()); |
| 35 | |
| 36 | cv::Mat bgr(color_image.size(), CV_8UC3); |
| 37 | cv::cvtColor(color_image, bgr, cv::COLOR_YUV2BGR_YUYV); |
| 38 | |
| 39 | cv::imshow("Replay", bgr); |
| 40 | cv::waitKey(1); |
| 41 | }); |
| 42 | |
| 43 | factory.Run(); |
| 44 | |
| 45 | reader.Deregister(); |
| 46 | |
| 47 | return 0; |
| 48 | } |