reptily/php-image-diff

1.0.0 2021-10-12 16:46 UTC

This package is not auto-updated.

Last update: 2024-09-26 05:41:59 UTC


README

composer require reptily/php-image-diff

示例

  1. 一个简单的示例,用于确定两张图像之间的差异。

第一张图像

第二张图像

<?php

require __DIR__ . '/vendor/autoload.php';

$image = new ImageDiff\Compares("1.png", "2.png");
try {
    $image->Diff();
    $image->getDiffImage("diff.png");
} catch (Exception $e) {
    var_dump($e);
}

结果图像比较

  1. 用于监控摄像头的示例。比较区域定义。

第一张图像

第二张图像

<?php

require __DIR__ . '/vendor/autoload.php';

$image = new ImageDiff\Compares("1m.png", "2m.png");
$area = (new ImageDiff\Model\Area())
    ->setPositionX(350)
    ->setPositionY(50)
    ->setSizeWidth(190)
    ->setSizeHeight(160)
;
try {
    $image->Diff(5.0, $area);
    $result = $image->Result();
    echo "Count all pixels: " . $result->getCountAllPixels() . "\n";
    echo "Count error pixels: " . $result->getCountErrorPixels() . "\n";
    echo "Error percentage: " . $result->getErrorPercentage() . "%\n";
    $image->getDiffImage("diff.png");
} catch (Exception $e) {
    var_dump($e);
}

打印结果

Count all pixels: 219375
Count error pixels: 6455
Error percentage: 2.9424501424501%

结果图像比较