From 655abc914b5c7ae066ae0101fd4b3b7d64b45002 Mon Sep 17 00:00:00 2001 From: Peter Woolery Date: Mon, 13 Apr 2026 14:41:11 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20CV=20find=5Fcentroids=20=E2=80=94=20stat?= =?UTF-8?q?ic=20fg=5Fcopy=20to=20prevent=209KB=20stack=20allocation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- firmware/lib/cv/cv.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/lib/cv/cv.cpp b/firmware/lib/cv/cv.cpp index 552b84d..ca4186c 100644 --- a/firmware/lib/cv/cv.cpp +++ b/firmware/lib/cv/cv.cpp @@ -17,6 +17,8 @@ void cv_reset_counts(CVState& state) { struct Point { int x, y; }; +// Note: queue may grow to CV_PIXELS entries (~72KB) on large blobs. +// Requires PSRAM (enabled via -DBOARD_HAS_PSRAM in platformio.ini). // BFS flood fill. Marks visited pixels (sets fg to 0). Returns {-1,-1} if blob < CV_MIN_BLOB_PX. static std::pair extract_blob(uint8_t* fg, int start_x, int start_y) { std::vector queue; @@ -49,7 +51,7 @@ static std::pair extract_blob(uint8_t* fg, int start_x, int start_y static std::vector> find_centroids(const uint8_t* fg) { std::vector> result; - uint8_t fg_copy[CV_PIXELS]; + static uint8_t fg_copy[CV_PIXELS]; // static to avoid 9KB stack allocation memcpy(fg_copy, fg, CV_PIXELS); for (int y = 0; y < CV_H; y++) {