drawSegmentationClassLabels function

void drawSegmentationClassLabels(
  1. Canvas canvas,
  2. List<int> counts,
  3. List<double> sumX,
  4. List<double> sumY,
)

Draw multiclass segmentation labels at class centroids (one label per class index whose pixel count exceeds an internal threshold).

Implementation

void drawSegmentationClassLabels(
  Canvas canvas,
  List<int> counts,
  List<double> sumX,
  List<double> sumY,
) {
  for (int c = 0; c < 6; c++) {
    if (counts[c] > 100) {
      final centroidX = sumX[c] / counts[c];
      final centroidY = sumY[c] / counts[c];
      final textPainter = TextPainter(
        text: TextSpan(
          text: kSegmentationClassLabels[c],
          style: const TextStyle(
            color: Colors.white,
            fontSize: 10,
            fontWeight: FontWeight.bold,
            shadows: [
              Shadow(color: Colors.black, blurRadius: 2),
              Shadow(color: Colors.black, blurRadius: 4),
            ],
          ),
        ),
        textDirection: TextDirection.ltr,
      );
      textPainter.layout();
      textPainter.paint(
        canvas,
        Offset(
          centroidX - textPainter.width / 2,
          centroidY - textPainter.height / 2,
        ),
      );
    }
  }
}