1

画像の知覚ハッシュを計算する必要があり、外部ライブラリを使用せずに計算する必要があります。

pHash(http://phash.org/)を使用してみましたが、iOS(5)用にコンパイルできず、その方法に関する実際のチュートリアルが見つかりませんでした。

4

1 に答える 1

0

1 つの (ライブラリ依存の) 解決策は、バージョン 6.8.8.3 で ImageMagick に追加された pHashing 機能を使用することです。この機能には、iOS バイナリが利用可能です。使用例はここに文書化されています。

このブログにある、比較可能な独自の画像平均ハッシュを生成するための簡単な参照関数 (C#) もここにあります。

public static ulong AverageHash(System.Drawing.Image theImage)
// Calculate a hash of an image based on visual characteristics.
// Described at http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
{
    // Squeeze the image down to an 8x8 image.
    // Chant the ancient incantations to create the correct data structures.
    Bitmap squeezedImage = new Bitmap(8, 8, PixelFormat.Format32bppRgb);
    Graphics drawingArea = Graphics.FromImage(squeezedImage);
        drawingArea.CompositingQuality = CompositingQuality.HighQuality;
        drawingArea.InterpolationMode = InterpolationMode.HighQualityBilinear;
        drawingArea.SmoothingMode = SmoothingMode.HighQuality;
        drawingArea.DrawImage(theImage, 0, 0, 8, 8);

    byte[] grayScaleImage = new byte[64];

    uint averageValue = 0;
    ulong finalHash = 0;

    // Reduce to 8-bit grayscale and calculate the average pixel value.
    for(int y = 0; y < 8; y++)
    {
        for(int x = 0; x < 8; x++)
        {
            Color pixelColour = squeezedImage.GetPixel(x,y);
            uint grayTone = ((uint)((pixelColour.R * 0.3) + (pixelColour.G * 0.59) + (pixelColour.B * 0.11)));

            grayScaleImage[x + y*8] = (byte)grayTone;
            averageValue += grayTone;
        }
    }
    averageValue /= 64;

    // Return 1-bits when the tone is equal to or above the average,
    // and 0-bits when it's below the average.
    for(int k = 0; k < 64; k++)
    {
        if(grayScaleImage[k] >= averageValue)
        {
            finalHash |= (1UL << (63-k));
        }
    }

    return finalHash;
}
于 2014-08-01T22:47:57.250 に答える