與php中輸入的影像進行比較後,在目錄中輸出相似的影像
P粉245003607
P粉245003607 2024-01-29 14:38:39
0
1
463

在我的網頁中,使用者將上傳圖像,然後在提交後應將其與目錄中的所有圖像進行比較並輸出相似的圖像。我用md5 做到了這一點,但它只會輸出精確的圖像,我知道原因,但我不知道如何使用RGB 比較將我的目錄中的所有圖像與輸入的圖像循環...有人可以幫助我嗎?這是我目前的程式碼:

<?php 
    if(isset($_POST['submit'])){

    $filepath=pathinfo($_FILES['file']['name']) ;
    $extension=$filepath['extension'];
    
    $iname= date('H-i-s').'.'.$extension;
    $path='upload/'.$iname;
    if(move_uploaded_file($_FILES['file']['tmp_name'],$path)){
        $img=$path;
        echo $img;
        $f=md5(file_get_contents($img));
        $images=glob("img/*");
        foreach($images as $image){
            if($f==md5(file_get_contents($image))){
                echo  "<img height='70px' width='70px' src='".$image."'/>";
            }

        }


    
}
}
?>

還有我的 html 程式碼

<html>
     <body> 
       <form method=post enctype="multipart/form-data">
          <input type=file name=file><br><input type=submit name=submit value=submit>
       </form>
    </body>
   </html>

P粉245003607
P粉245003607

全部回覆(1)
P粉860897943

我使用了此 git 儲存庫中提到的類別來計算圖像雜湊值及其差異。

https://github.com/nvthaovn/CompareImage

#並將我的程式碼更改為:

<?php 
include('compareImages.php');
$flag = 0;

if(isset($_POST['submit'])) {

    $filepath = pathinfo($_FILES['file']['name']);
    $extension = $filepath['extension'];
    
    $iname = date('H-i-s').'.'.$extension;
    $path = 'upload/'.$iname;

    if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
        
        $compareMachine = new compareImages($path);
        $images = glob("img/*");

        foreach($images as $image)
        {
            $diff = $compareMachine->compareWith($image);
            
            if($diff ";
            }
        }
        
        $flag = 1;
    }
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!