IntegralImage.fromImage constructor
IntegralImage.fromImage(
- FaceImage image
Creates an IntegralImage from a grayscale FaceImage.
Implementation
factory IntegralImage.fromImage(FaceImage image) {
final gray = image.format == ImageFormat.grayscale
? image
: image.toGrayscale();
final w = gray.width;
final h = gray.height;
final tableWidth = w + 1;
final tableHeight = h + 1;
final table = Int32List(tableWidth * tableHeight);
final buf = gray.buffer;
for (var y = 0; y < h; y++) {
int rowSum = 0;
final srcRowOff = y * w;
final dstRowOff = (y + 1) * tableWidth;
final prevDstRowOff = y * tableWidth;
for (var x = 0; x < w; x++) {
rowSum += buf[srcRowOff + x];
table[dstRowOff + (x + 1)] = table[prevDstRowOff + (x + 1)] + rowSum;
}
}
return IntegralImage._(w, h, table);
}