listCompare function

Future<List<double>> listCompare({
  1. required dynamic target,
  2. required List list,
  3. Algorithm? algorithm,
})

Compare target to each image present in list using a specified algorithm. If algorithm is not specified, the default (PixelMatching()) is supplied.

Returns a Future list of doubles corresponding to the difference between targetSrc and srcListi. Output is in the same order as srcList.

target and listi may be any combination of the supported types:

  • Uri - parsed URI, such as a URL (dart:core Uri class)
  • File - reference to a file on the file system (dart:io File class)
  • List- list of integers (bytes representing the image)
  • Image - image buffer (Image class)

Implementation

Future<List<double>> listCompare({
  required var target,
  required List<dynamic> list,
  Algorithm? algorithm,
}) async {
  algorithm ??= PixelMatching(); //default algorithm

  var results = List<double>.filled(list.length, 0);

  await Future.wait(list.map((otherSrc) async {
    results[list.indexOf(otherSrc)] =
        await compareImages(src1: target, src2: otherSrc, algorithm: algorithm);
  }));

  return results;
}