Jim Ostrowski | 23eb658 | 2020-03-04 23:15:32 -0800 | [diff] [blame^] | 1 | #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 | |
| 10 | DEFINE_string(config, "config.json", "Path to the config file to use."); |
| 11 | |
| 12 | namespace frc971 { |
| 13 | namespace vision { |
| 14 | namespace { |
| 15 | |
| 16 | void 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 |
| 43 | int main(int argc, char **argv) { |
| 44 | aos::InitGoogle(&argc, &argv); |
| 45 | frc971::vision::ViewerMain(); |
| 46 | } |