使用PHP使用感知散列或其他技术检测类似的图像

时间:2018-02-22 02:36:25

标签: php image hash similarity detect

我有20张JPG图片:

enter image description here

我需要检测这10个相似的图像:

enter image description here

我尝试使用上面的代码 Perceptual hash implementation for PHP

<?php

    $scandir = array_values(array_diff(scandir("images"), array(".", "..", ".DS_Store")));
    natsort($scandir);

    include('phash.php');

    foreach ($scandir as $key => $value){
    $phasher = new Phash;

    $phash2 = $phasher->getHash("image-fragment-to-compare.jpg", false);
    echo $phasher->hashAsString($phash2, false).PHP_EOL;
    echo $phasher->hashAsString($phash2).PHP_EOL;

    $phash3 = $phasher->getHash("images/$value", false);
    echo $phasher->hashAsString($phash3, false).PHP_EOL;
    echo $phasher->hashAsString($phash3).PHP_EOL;

    $compare = $phasher->getSimilarity($phash2, $phash3);
    echo "compare image-fragment-to-compare.jpg with images/$value = $compare \n";
    }

?>

我尝试使用不同的image-fragment-to-compare.jpg片段,例如“键盘”片段,“闪电键”片段,灰色背景。它检测不坏,但不理想。有没有其他灵魂的PHP可以更准确地检测这些图像?

0 个答案:

没有答案