VisionCleanup:
  - Minor cleanup and bug fixes.
  - Update sender parameters.
  - Enable Slower Threshold.
  - Cleanup from code review.

Change-Id: I5f6ea77b42d6520e120379a5efbd312c2467c811
diff --git a/y2019/vision/debug_viewer.cc b/y2019/vision/debug_viewer.cc
index 533dcf6..1db8e33 100644
--- a/y2019/vision/debug_viewer.cc
+++ b/y2019/vision/debug_viewer.cc
@@ -150,15 +150,14 @@
     // Use the solver to generate an intermediate version of our results.
     std::vector<IntermediateResult> results;
     for (const Target &target : target_list) {
-      results.emplace_back(finder_.ProcessTargetToResult(target, true));
+      results.emplace_back(finder_.ProcessTargetToResult(target, draw_raw_IR_));
       if (draw_raw_IR_) DrawResult(results.back(), {255, 128, 0});
     }
 
     // Check that our current results match possible solutions.
-    results = finder_.FilterResults(results);
+    results = finder_.FilterResults(results, 0);
     if (draw_results_) {
       for (const IntermediateResult &res : results) {
-        DrawResult(res, {0, 255, 0});
         DrawTarget(res, {0, 255, 0});
       }
     }
@@ -194,7 +193,7 @@
         printf(" n: Toggle drawing countours before and after warping.\n");
         printf(" m: Toggle drawing raw blob data (may need to change image to toggle a redraw).\n");
         printf(" h: Print this message.\n");
-        printf(" a: May log camera image to /tmp/debug_viewer_jpeg_<#>.yuyv"
+        printf(" a: May log camera image to /tmp/debug_viewer_jpeg_<#>.yuyv\n");
         printf(" q: Exit the application.\n");
       } else if (key == 'q') {
         printf("User requested shutdown.\n");
diff --git a/y2019/vision/target_finder.cc b/y2019/vision/target_finder.cc
index b46d802..be2e262 100644
--- a/y2019/vision/target_finder.cc
+++ b/y2019/vision/target_finder.cc
@@ -419,13 +419,24 @@
 }
 
 std::vector<IntermediateResult> TargetFinder::FilterResults(
-    const std::vector<IntermediateResult> &results) {
+    const std::vector<IntermediateResult> &results, uint64_t print_rate) {
   std::vector<IntermediateResult> filtered;
   for (const IntermediateResult &res : results) {
     if (res.solver_error < 75.0) {
       filtered.emplace_back(res);
     }
   }
+  frame_count_++;
+  if (!filtered.empty()) {
+    valid_result_count_++;
+  }
+  if (print_rate > 0 && frame_count_ > print_rate) {
+    LOG(INFO, "Found (%zu / %zu)(%.2f) targets.\n", valid_result_count_,
+        frame_count_, (double)valid_result_count_ / (double)frame_count_);
+    frame_count_ = 0;
+    valid_result_count_ = 0;
+  }
+
   return filtered;
 }
 
diff --git a/y2019/vision/target_finder.h b/y2019/vision/target_finder.h
index bdf67f2..4583690 100644
--- a/y2019/vision/target_finder.h
+++ b/y2019/vision/target_finder.h
@@ -49,7 +49,7 @@
   IntermediateResult ProcessTargetToResult(const Target &target, bool verbose);
 
   std::vector<IntermediateResult> FilterResults(
-      const std::vector<IntermediateResult> &results);
+      const std::vector<IntermediateResult> &results, uint64_t print_rate);
 
   // Get the local overlay for debug if we are doing that.
   aos::vision::PixelLinesOverlay *GetOverlay() { return &overlay_; }
@@ -78,6 +78,10 @@
   IntrinsicParams intrinsics_;
 
   ExtrinsicParams default_extrinsics_;
+
+  // Counts for logging.
+  size_t frame_count_;
+  size_t valid_result_count_;
 };
 
 }  // namespace vision
diff --git a/y2019/vision/target_sender.cc b/y2019/vision/target_sender.cc
index 2c7d8e2..688c676 100644
--- a/y2019/vision/target_sender.cc
+++ b/y2019/vision/target_sender.cc
@@ -289,12 +289,11 @@
 
   TargetFinder finder_;
 
-  // Check that our current results match possible solutions.
   aos::vision::CameraParams params0;
-  params0.set_exposure(400);
+  params0.set_exposure(50);
   params0.set_brightness(40);
   params0.set_width(640);
-  // params0.set_fps(10);
+  params0.set_fps(15);
   params0.set_height(480);
 
   ::std::unique_ptr<CameraStream> camera0(
@@ -302,9 +301,11 @@
   camera0->set_on_frame([&](DataRef data,
                             monotonic_clock::time_point monotonic_now) {
     aos::vision::ImageFormat fmt{640, 480};
+    // Use threshold from aos::vision. This will run at 15 FPS.
     aos::vision::BlobList imgs =
-        aos::vision::FindBlobs(::DoThresholdYUYV(fmt, data.data(), 120));
+        aos::vision::FindBlobs(aos::vision::DoThresholdYUYV(fmt, data.data(), 120));
     finder_.PreFilter(&imgs);
+    LOG(INFO, "Blobs: (%zu).\n", imgs.size());
 
     bool verbose = false;
     std::vector<std::vector<Segment<2>>> raw_polys;
@@ -317,22 +318,27 @@
         raw_polys.push_back(polygon);
       }
     }
+    LOG(INFO, "Polygons: (%zu).\n", raw_polys.size());
 
     // Calculate each component side of a possible target.
     std::vector<TargetComponent> target_component_list =
         finder_.FillTargetComponentList(raw_polys);
+    LOG(INFO, "Components: (%zu).\n", target_component_list.size());
 
     // Put the compenents together into targets.
     std::vector<Target> target_list =
         finder_.FindTargetsFromComponents(target_component_list, verbose);
+    LOG(INFO, "Potential Target: (%zu).\n", target_list.size());
 
     // Use the solver to generate an intermediate version of our results.
     std::vector<IntermediateResult> results;
     for (const Target &target : target_list) {
       results.emplace_back(finder_.ProcessTargetToResult(target, verbose));
     }
+    LOG(INFO, "Raw Results: (%zu).\n", results.size());
 
-    results = finder_.FilterResults(results);
+    results = finder_.FilterResults(results, 30);
+    LOG(INFO, "Results: (%zu).\n", results.size());
 
     // TODO: Select top 3 (randomly?)
 
diff --git a/y2019/vision/tools/deploy.sh b/y2019/vision/tools/deploy.sh
index ff3ee01..7cedfb0 100755
--- a/y2019/vision/tools/deploy.sh
+++ b/y2019/vision/tools/deploy.sh
@@ -7,8 +7,11 @@
     //y2019/vision:target_sender \
     //y2019/vision:serial_waiter
 
-echo "Mount jevois ..."
-./jevois-cmd usbsd
+if [ ! -d /media/$USER/JEVOIS ]
+then
+  echo "Mount jevois at /media/$USER/JEVOIS ..."
+  ./jevois-cmd usbsd
+fi
 
 echo "Waiting for fs ..."
 while [ ! -d /media/$USER/JEVOIS ]
diff --git a/y2019/vision/tools/flash.sh b/y2019/vision/tools/flash.sh
index 5daad73..5cef493 100755
--- a/y2019/vision/tools/flash.sh
+++ b/y2019/vision/tools/flash.sh
@@ -6,6 +6,19 @@
   exit
 fi
 
+echo "Pulling Binaries ..."
+if [ ! -f "./libjevoisbase.so" ]
+then
+  wget http://www.frc971.org/Build-Dependencies/libjevoisbase.so
+fi
+echo "Got libjevoisbase.so"
+
+if [ ! -f "./PassThrough.so" ]
+then
+  wget http://www.frc971.org/Build-Dependencies/PassThrough.so
+fi
+echo "Got PassThrough.so"
+
 DEV_BASE=/dev/mmcblk0p
 
 echo "Please check that ${DEV_BASE}3 is the correct drive to format. This is a destructive command so please be sure."
@@ -30,15 +43,20 @@
 
 echo "Make JEVOIS directories."
 mkdir -p /tmp/JEVOIS/packages
-mkdir -p /tmp/JEVOIS/modules
+mkdir -p /tmp/JEVOIS/modules/JeVois/PassThrough/
 mkdir -p /tmp/JEVOIS/config
-mkdir -p /tmp/JEVOIS/lib
+mkdir -p /tmp/JEVOIS/lib/JeVois/
+mkdir -p /tmp/JEVOIS/deploy/
+mkdir -p /tmp/JEVOIS/data/
 
 echo "Copy configs."
 cp ./austin_cam.sh /tmp/JEVOIS
 cp ./videomappings.cfg /tmp/JEVOIS/config/
 cp ./rcS_script.txt /tmp/LINUX/etc/init.d/rcS
 cp Jevois_fstab /tmp/LINUX/etc/fstab
+cp ./PassThrough.so /tmp/JEVOIS/modules/JeVois/PassThrough/
+cp ./libjevoisbase.so /tmp/JEVOIS/lib/JeVois/
+cp ./launch.sh /tmp/JEVOIS/deploy/
 
 echo "Un-mounting JEVOIS"
 sudo umount /tmp/JEVOIS