Filter blobs based on aspect ratio and size

Signed-off-by: milind-u <milind.upadhyay@gmail.com>
Change-Id: Idad861a777a9f09de7da10792ce5ab73c5daa6d1
diff --git a/y2022/vision/blob_detector.h b/y2022/vision/blob_detector.h
index 3da3d4b..84e504d 100644
--- a/y2022/vision/blob_detector.h
+++ b/y2022/vision/blob_detector.h
@@ -1,6 +1,7 @@
 #ifndef Y2022_BLOB_DETECTOR_H_
 #define Y2022_BLOB_DETECTOR_H_
 
+#include <opencv2/features2d.hpp>
 #include <opencv2/imgproc.hpp>
 
 namespace y2022 {
@@ -8,6 +9,13 @@
 
 class BlobDetector {
  public:
+  struct BlobStats {
+    cv::Point centroid;
+    double aspect_ratio;
+    double area;
+    size_t points;
+  };
+
   BlobDetector() {}
   // Given an image, threshold it to find "green" pixels
   // Input: Color image
@@ -17,25 +25,28 @@
   // Given binary image, extract blobs
   static std::vector<std::vector<cv::Point>> FindBlobs(cv::Mat threshold_image);
 
+  // Extract stats for each blob
+  static std::vector<BlobStats> ComputeStats(
+      std::vector<std::vector<cv::Point>> blobs);
+
   // Filter blobs to get rid of noise, too large items, etc.
   static std::vector<std::vector<cv::Point>> FilterBlobs(
-      std::vector<std::vector<cv::Point>> blobs);
+      std::vector<std::vector<cv::Point>> blobs,
+      std::vector<BlobStats> blob_stats);
 
   // Draw Blobs on image
   // Optionally draw all blobs and filtered blobs
-  static void DrawBlobs(cv::Mat view_image,
-                        std::vector<std::vector<cv::Point>> filtered_blobs,
-                        std::vector<std::vector<cv::Point>> unfiltered_blobs);
-
-  // Extract stats for each blob
-  static std::vector<std::vector<cv::Point>> ComputeStats(
-      std::vector<std::vector<cv::Point>>);
+  static void DrawBlobs(
+      cv::Mat view_image,
+      const std::vector<std::vector<cv::Point>> &filtered_blobs,
+      const std::vector<std::vector<cv::Point>> &unfiltered_blobs,
+      const std::vector<BlobStats> &blob_stats);
 
   static void ExtractBlobs(
       cv::Mat rgb_image, cv::Mat binarized_image, cv::Mat blob_image,
       std::vector<std::vector<cv::Point>> &filtered_blobs,
       std::vector<std::vector<cv::Point>> &unfiltered_blobs,
-      std::vector<std::vector<cv::Point>> &blob_stats);
+      std::vector<BlobStats> &blob_stats);
 };
 }  // namespace vision
 }  // namespace y2022