图像比较自动

问题描述 投票:3回答:1

有没有办法在文件夹中查找类似的图像,但具有不同的尺寸或较小的差异,比如说90%匹配。

我更喜欢一个示例代码或外部插件或任何库函数(我不知道任何库函数没有100%匹配,甚至校验和是不可能的。我已经尝试了所有这些无效的结果。)

autoit image-recognition image-comparison
1个回答
1
投票

取自my answer another post,这通常会检查它们是否重复。您可以调整它来做您需要的事情。

CompareImagesUDF.au3

Func _CompareImages($ciImageOne, $ciImageTwo)
    _GDIPlus_Startup()

    $fname1 = $ciImageOne
    If $fname1 = "" Then Exit

    $fname2 = $ciImageTwo
    If $fname2="" Then Exit

    $bm1 = _GDIPlus_ImageLoadFromFile($fname1)
    $bm2 = _GDIPlus_ImageLoadFromFile($fname2)

    ; MsgBox(0, "bm1==bm2", CompareBitmaps($bm1, $bm2))
    Return CompareBitmaps($bm1, $bm2)

    _GDIPlus_ImageDispose($bm1)
    _GDIPlus_ImageDispose($bm2)
    _GDIPlus_Shutdown()
EndFunc

Func CompareBitmaps($bm1, $bm2)
    $Bm1W        = _GDIPlus_ImageGetWidth($bm1)
    $Bm1H        = _GDIPlus_ImageGetHeight($bm1)
    $BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)

    $Stride      = DllStructGetData($BitmapData1, "Stride")
    $Scan0       = DllStructGetData($BitmapData1, "Scan0")

    $ptr1        = $Scan0
    $size1       = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4

    $Bm2W        = _GDIPlus_ImageGetWidth($bm2)
    $Bm2H        = _GDIPlus_ImageGetHeight($bm2)
    $BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)

    $Stride      = DllStructGetData($BitmapData2, "Stride")
    $Scan0       = DllStructGetData($BitmapData2, "Scan0")

    $ptr2        = $Scan0
    $size2       = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4
    $smallest    = $size1

    If $size2 < $smallest Then $smallest = $size2

    $call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)

    _GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
    _GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)

    Return $call[0]=0
EndFunc

要比较图像,请包含CompareImagesUDF.au3并调用该函数。

CompareImagesExample.au3

#Include "CompareImagesUDF.au3"

; Define the two images (They can be different file formats)
$img1 = "Image1.jpg"
$img2 = "Image2.jpg"

; Compare the two images
$duplicateCheck = _CompareImages($img1, $img2)
MsgBox(0,"Is Duplicate?", $duplicateCheck)
© www.soinside.com 2019 - 2024. All rights reserved.