Add --capture to viewer for saving an image

This makes it significantly easier to capture images when re-training.

Change-Id: Ie6a106360cb0a7f747f07021cbd34cf5518bff02
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/y2020/vision/viewer.cc b/y2020/vision/viewer.cc
index 5da2dbe..c141e3c 100644
--- a/y2020/vision/viewer.cc
+++ b/y2020/vision/viewer.cc
@@ -15,6 +15,9 @@
 DEFINE_bool(show_features, true, "Show the SIFT features that matched.");
 DEFINE_string(channel, "/camera", "Channel name for the image.");
 
+DEFINE_string(capture, "",
+              "If set, capture a single image and save it to this filename.");
+
 namespace frc971 {
 namespace vision {
 namespace {
@@ -68,6 +71,11 @@
   cv::Mat rgb_image(cv::Size(image->cols(), image->rows()), CV_8UC3);
   cv::cvtColor(image_color_mat, rgb_image, CV_YUV2BGR_YUYV);
 
+  if (!FLAGS_capture.empty()) {
+    cv::imwrite(FLAGS_capture, rgb_image);
+    return false;
+  }
+
   if (matching_image_found) {
     // Draw whatever matches we have
     if (match->camera_poses() != nullptr && match->camera_poses()->size() > 0) {
@@ -154,6 +162,9 @@
       ::std::chrono::milliseconds(100));
 
   event_loop.Run();
+
+  image_fetcher = aos::Fetcher<CameraImage>();
+  match_fetcher = aos::Fetcher<sift::ImageMatchResult>();
 }
 
 }  // namespace