繁体   English   中英

如何使用 ImageMagick 或 GraphicsMagick Node.js 从图像中获取哈希值?

[英]How to get hash value from image using ImageMagick or GraphicsMagick Node.js?

查看这两个节点包的文档:

https://github.com/aheckmann/gm

https://github.com/rsms/node-imagemagick

试图弄清楚是否可以使用它生成图像的感知哈希。

我已经在我的项目中使用了这些包,所以很高兴找到散列功能而不是像 Jimp 那样添加额外的包。

任何形式的帮助都非常感谢!

编辑 1:

因此,在查看了你们的所有链接和建议后,我尝试遵循

    gm()
    .command("convert")
    .in("testImage.jpeg")
    .in("-verbose")
    .in("-moments")
    .write( "testOutput.json", function (err) {
        if (!err) {
            console.log("DONE :)");
        }
        else {
            console.log("ERROR :(");
            console.log(err);
        }
    });

它给了我巨大的输出,但我感兴趣的部分在这里:

"channelPerceptualHash": {
      "colorspaces": [ "sRGB", "HCLp"],
      "Channel0": {
        "PH1": [0.514487, 11],
        "PH2": [3.46339, 11],
        "PH3": [4.96178, 11],
        "PH4": [5.09255, 11],
        "PH5": [10.2783, 11],
        "PH6": [7.0728, 11],
        "PH7": [10.2625, 11]
      },
      "Channel1": {
        "PH1": [0.514487, 11],
        "PH2": [3.46339, 11],
        "PH3": [4.96178, 11],
        "PH4": [5.09255, 11],
        "PH5": [10.2783, 11],
        "PH6": [7.0728, 11],
        "PH7": [10.2625, 11]
      },
      "Channel2": {
        "PH1": [0.514487, 0.514487],
        "PH2": [3.46339, 3.46339],
        "PH3": [4.96178, 4.96178],
        "PH4": [5.09255, 5.09255],
        "PH5": [10.2783, 10.2783],
        "PH6": [7.0728, 7.0728],
        "PH7": [10.2625, 10.2625]
      }
    },
    "renderingIntent": "Perceptual"

根据这个线程http://www.imagemagick.org/discourse-server/viewtopic.php?t=30258

如果我没记错的话,我可以通过比较这些 PH 值来确定图像是否相同。

回答改进了从@fmw42 收到的建议

AFAIK,您的 2 个链接中的第一个更相关,并且 3 年没有维护,所以我不抱希望。

在命令行中,它将是:

identify -verbose -moments image.png

所以我下载了这些包的源代码并像这样搜索momenthashperceptual

find . -type f -exec grep -Ei "moment|hash|perceptual" {} +

唯一的输出与感知哈希无关,只是一般的图像哈希和感知渲染意图:

./test/selectFrame.js:  m.identify('%#', function (err, hash1) {
./test/selectFrame.js:    m.selectFrame(2).identify('%#', function (err, hash2) {
./test/selectFrame.js:      assert.ok(hash1.toString().trim() !== hash2.toString().trim())
./test/getterIdentify.js:        assert.equal(d['Rendering intent'], 'Perceptual');

我不抱希望,但很高兴在错误时得到纠正。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM