compareImages function
Future<double>
compareImages({
- required dynamic src1,
- required dynamic src2,
- Algorithm? algorithm,
Compare images from src1
and src2
with a specified algorithm
.
If algorithm
is not specified, the default (PixelMatching()) is supplied.
Returns a Future of double corresponding to the difference between src1
and src2
src1
and src2
may be any combination of the supported types:
Implementation
Future<double> compareImages({
required var src1,
required var src2,
Algorithm? algorithm,
}) async {
algorithm ??= PixelMatching(); // default algorithm
src1 = await _getImageFromDynamic(src1);
src2 = await _getImageFromDynamic(src2);
var result = algorithm.compare(src1, src2);
// Ignore floating point error
if (result < 0) {
result = 0;
} else if (result > 1) {
result = 1;
}
return result;
}