Limit blob debug output in 2022 camera_reader
If we got a huge number of blobs, camera reader would crash because of
trying to allocate too large of a flatbuffer message.
Also, the TargetEstimate message does need to make it across the network
without too high of latency, so excessive debug information in it would
be sub-optimal.
Change-Id: I394c909b4c66940451b3ea2b90f6dc8d383420f6
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/y2022/vision/camera_reader.cc b/y2022/vision/camera_reader.cc
index 2be2ef1..f1cb4e8 100644
--- a/y2022/vision/camera_reader.cc
+++ b/y2022/vision/camera_reader.cc
@@ -50,6 +50,8 @@
return builder->fbb()->CreateVectorOfStructs(points_fbs);
}
+constexpr size_t kMaxBlobsForDebug = 100;
+
// Converts a vector of cv::Point to PointT for the flatbuffer
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Blob>>>
CvBlobsToFbs(const std::vector<std::vector<cv::Point>> &blobs,
@@ -60,6 +62,9 @@
auto blob_builder = builder->MakeBuilder<Blob>();
blob_builder.add_points(points_offset);
blobs_fbs.emplace_back(blob_builder.Finish());
+ if (blobs_fbs.size() == kMaxBlobsForDebug) {
+ break;
+ }
}
return builder->fbb()->CreateVector(blobs_fbs.data(), blobs_fbs.size());
}