Stephan Pleines | cc500b9 | 2024-05-30 10:58:40 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | #include "aos/time/time.h" |
Parker Schuh | 57ba10c | 2017-03-04 17:46:53 -0800 | [diff] [blame] | 7 | #include "aos/vision/events/epoll_events.h" |
Stephan Pleines | cc500b9 | 2024-05-30 10:58:40 -0700 | [diff] [blame] | 8 | #include "aos/vision/image/camera_params.pb.h" |
Parker Schuh | 57ba10c | 2017-03-04 17:46:53 -0800 | [diff] [blame] | 9 | #include "aos/vision/image/image_stream.h" |
Stephan Pleines | cc500b9 | 2024-05-30 10:58:40 -0700 | [diff] [blame] | 10 | #include "aos/vision/image/image_types.h" |
Parker Schuh | 57ba10c | 2017-03-04 17:46:53 -0800 | [diff] [blame] | 11 | |
| 12 | class ImageStream : public aos::vision::ImageStreamEvent { |
| 13 | public: |
Parker Schuh | 24ee58d | 2017-03-11 16:13:23 -0800 | [diff] [blame] | 14 | ImageStream(const std::string &fname, aos::vision::CameraParams params) |
Parker Schuh | 57ba10c | 2017-03-04 17:46:53 -0800 | [diff] [blame] | 15 | : ImageStreamEvent(fname, params) {} |
| 16 | void ProcessImage(aos::vision::DataRef /*data*/, |
| 17 | aos::monotonic_clock::time_point) override { |
| 18 | if (i_ > 20) { |
| 19 | exit(0); |
| 20 | } |
| 21 | ++i_; |
| 22 | } |
| 23 | |
| 24 | private: |
| 25 | int i_ = 0; |
| 26 | }; |
| 27 | |
| 28 | // camera_primer drops the first 20 frames. This is to get around issues |
| 29 | // where the first N frames from the camera are garbage. Thus each year |
| 30 | // you should write a startup script like so: |
| 31 | // |
| 32 | // camera_primer |
| 33 | // target_sender |
| 34 | int main(int argc, char **argv) { |
Parker Schuh | 24ee58d | 2017-03-11 16:13:23 -0800 | [diff] [blame] | 35 | aos::vision::CameraParams params; |
Parker Schuh | 57ba10c | 2017-03-04 17:46:53 -0800 | [diff] [blame] | 36 | |
| 37 | if (argc != 2) { |
| 38 | fprintf(stderr, "usage: %s path_to_camera\n", argv[0]); |
| 39 | exit(-1); |
| 40 | } |
| 41 | ImageStream stream(argv[1], params); |
| 42 | |
| 43 | aos::events::EpollLoop loop; |
| 44 | loop.Add(&stream); |
| 45 | loop.Run(); |
| 46 | } |