blob: c81796a37211e501d29f8ca688d911fc6914f63a [file] [log] [blame]
James Kuszmaul8ae931a2020-03-06 19:45:02 -08001#include <opencv2/calib3d.hpp>
2#include <opencv2/features2d.hpp>
3#include <opencv2/highgui/highgui.hpp>
4#include <opencv2/imgproc.hpp>
5
6#include "aos/events/logging/logger.h"
7#include "aos/events/simulated_event_loop.h"
8#include "aos/init.h"
9#include "y2020/vision/vision_generated.h"
10
11DEFINE_string(config, "y2020/config.json", "Path to the config file to use.");
12DEFINE_string(logfile, "", "Path to the log file to use.");
13DEFINE_string(node, "pi1", "Node name to replay.");
14
15namespace frc971 {
16namespace vision {
17namespace {
18
19void ViewerMain() {
20 CHECK(!FLAGS_logfile.empty()) << "You forgot to specify a logfile.";
21
22 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
23 aos::configuration::ReadConfig(FLAGS_config);
24
25 aos::logger::LogReader reader(FLAGS_logfile, &config.message());
26 reader.Register();
27 const aos::Node *node = nullptr;
28 if (aos::configuration::MultiNode(reader.configuration())) {
29 node = aos::configuration::GetNode(reader.configuration(), FLAGS_node);
30 }
31 std::unique_ptr<aos::EventLoop> event_loop =
32 reader.event_loop_factory()->MakeEventLoop("player", node);
33
34 event_loop->MakeWatcher("/camera", [](const CameraImage &image) {
35 cv::Mat image_mat(image.rows(), image.cols(), CV_8U);
36 CHECK(image_mat.isContinuous());
37 const int number_pixels = image.rows() * image.cols();
38 for (int i = 0; i < number_pixels; ++i) {
39 reinterpret_cast<uint8_t *>(image_mat.data)[i] =
40 image.data()->data()[i * 2];
41 }
42
43 cv::imshow("Display", image_mat);
44 cv::waitKey(1);
45 });
46
47 reader.event_loop_factory()->Run();
48}
49
50} // namespace
51} // namespace vision
52} // namespace frc971
53
54// Quick and lightweight grayscale viewer for images
55int main(int argc, char **argv) {
56 aos::InitGoogle(&argc, &argv);
57 frc971::vision::ViewerMain();
58}