Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame^] | 1 | #ifndef Y2022_BLOB_DETECTOR_H_ |
| 2 | #define Y2022_BLOB_DETECTOR_H_ |
| 3 | |
| 4 | #include <opencv2/imgproc.hpp> |
| 5 | |
| 6 | namespace y2022 { |
| 7 | namespace vision { |
| 8 | |
| 9 | class BlobDetector { |
| 10 | public: |
| 11 | BlobDetector() {} |
| 12 | // Given an image, threshold it to find "green" pixels |
| 13 | // Input: Color image |
| 14 | // Output: Grayscale (binarized) image with green pixels set to 255 |
| 15 | static cv::Mat ThresholdImage(cv::Mat rgb_image); |
| 16 | |
| 17 | // Given binary image, extract blobs |
| 18 | static std::vector<std::vector<cv::Point>> FindBlobs(cv::Mat threshold_image); |
| 19 | |
| 20 | // Filter blobs to get rid of noise, too large items, etc. |
| 21 | static std::vector<std::vector<cv::Point>> FilterBlobs( |
| 22 | std::vector<std::vector<cv::Point>> blobs); |
| 23 | |
| 24 | // Draw Blobs on image |
| 25 | // Optionally draw all blobs and filtered blobs |
| 26 | static void DrawBlobs(cv::Mat view_image, |
| 27 | std::vector<std::vector<cv::Point>> filtered_blobs, |
| 28 | std::vector<std::vector<cv::Point>> unfiltered_blobs); |
| 29 | |
| 30 | // Extract stats for each blob |
| 31 | static std::vector<std::vector<cv::Point>> ComputeStats( |
| 32 | std::vector<std::vector<cv::Point>>); |
| 33 | |
| 34 | static void ExtractBlobs( |
| 35 | cv::Mat rgb_image, cv::Mat binarized_image, cv::Mat blob_image, |
| 36 | std::vector<std::vector<cv::Point>> &filtered_blobs, |
| 37 | std::vector<std::vector<cv::Point>> &unfiltered_blobs, |
| 38 | std::vector<std::vector<cv::Point>> &blob_stats); |
| 39 | }; |
| 40 | } // namespace vision |
| 41 | } // namespace y2022 |
| 42 | |
| 43 | #endif // Y2022_BLOB_DETECTOR_H_ |