blob: be9b9804a47d8c3e38d3f2ff516aff6a7786e226 [file] [log] [blame]
Jim Ostrowski23eb6582020-03-04 23:15:32 -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/shm_event_loop.h"
7#include "aos/init.h"
8#include "y2020/vision/vision_generated.h"
9
10DEFINE_string(config, "config.json", "Path to the config file to use.");
11
12namespace frc971 {
13namespace vision {
14namespace {
15
16void ViewerMain() {
17 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
18 aos::configuration::ReadConfig(FLAGS_config);
19
20 aos::ShmEventLoop event_loop(&config.message());
21
22 event_loop.MakeWatcher("/camera", [](const CameraImage &image) {
23 cv::Mat image_mat(image.rows(), image.cols(), CV_8U);
24 CHECK(image_mat.isContinuous());
25 const int number_pixels = image.rows() * image.cols();
26 for (int i = 0; i < number_pixels; ++i) {
27 reinterpret_cast<uint8_t *>(image_mat.data)[i] =
28 image.data()->data()[i * 2];
29 }
30
31 cv::imshow("Display", image_mat);
32 cv::waitKey(1);
33 });
34
35 event_loop.Run();
36}
37
38} // namespace
39} // namespace vision
40} // namespace frc971
41
42// Quick and lightweight grayscale viewer for images
43int main(int argc, char **argv) {
44 aos::InitGoogle(&argc, &argv);
45 frc971::vision::ViewerMain();
46}