Add camera primer. This starts up the camera properly.

Change-Id: I8ad07919b27e2fea436026b9f9fdd86b54a4286a
diff --git a/aos/vision/tools/BUILD b/aos/vision/tools/BUILD
index 56bbb5b..ac6a6ff 100644
--- a/aos/vision/tools/BUILD
+++ b/aos/vision/tools/BUILD
@@ -17,3 +17,14 @@
     "//aos/vision/events:gtk_event",
   ],
 )
+
+cc_binary(
+  name = 'camera_primer',
+  srcs = ['camera_primer.cc'],
+  deps = [
+    '//aos/common/logging:logging',
+    '//aos/common/logging:implementations',
+    '//aos/vision/image:image_stream',
+    '//aos/vision/events:epoll_events',
+  ],
+)
diff --git a/aos/vision/tools/camera_primer.cc b/aos/vision/tools/camera_primer.cc
new file mode 100644
index 0000000..a431ac8
--- /dev/null
+++ b/aos/vision/tools/camera_primer.cc
@@ -0,0 +1,49 @@
+#include "aos/common/logging/implementations.h"
+#include "aos/common/logging/logging.h"
+#include "aos/vision/events/epoll_events.h"
+#include "aos/vision/image/image_stream.h"
+
+class ImageStream : public aos::vision::ImageStreamEvent {
+ public:
+  ImageStream(const std::string &fname, camera::CameraParams params)
+      : ImageStreamEvent(fname, params) {}
+  void ProcessImage(aos::vision::DataRef /*data*/,
+                    aos::monotonic_clock::time_point) override {
+    if (i_ > 20) {
+      exit(0);
+    }
+    ++i_;
+  }
+
+ private:
+  int i_ = 0;
+};
+
+// camera_primer drops the first 20 frames. This is to get around issues
+// where the first N frames from the camera are garbage. Thus each year
+// you should write a startup script like so:
+//
+// camera_primer
+// target_sender
+int main(int argc, char **argv) {
+  ::aos::logging::Init();
+  ::aos::logging::AddImplementation(
+      new ::aos::logging::StreamLogImplementation(stdout));
+
+  camera::CameraParams params = {.width = 640 * 2,
+                                 .height = 480 * 2,
+                                 .exposure = 10,
+                                 .brightness = 128,
+                                 .gain = 0,
+                                 .fps = 30};
+
+  if (argc != 2) {
+    fprintf(stderr, "usage: %s path_to_camera\n", argv[0]);
+    exit(-1);
+  }
+  ImageStream stream(argv[1], params);
+
+  aos::events::EpollLoop loop;
+  loop.Add(&stream);
+  loop.Run();
+}