【问题标题】:Image comparison library for node.jsnode.js 的图像比较库
【发布时间】:2015-05-10 18:00:33
【问题描述】:

我正在寻找支持 node.js 或 linux 标准库的基本图像比较库。支持比较多分辨率图像和轻微的颜色变化会很棒。有什么建议吗?

【问题讨论】:

    标签: node.js image opencv machine-learning computer-vision


    【解决方案1】:

    嘿,RembrandtJS 可能正是您正在寻找的。 这是我们刚刚发布的一个轻量级库,它使用插入式 Node.JS 替换节点画布进行像素级图像比较。 它接受 blob 和 url 作为图像源,因此您可以简单地这样做:

    import Rembrandt from 'rembrandt'
    
    const rembrandt = new Rembrandt({
      // `imageA` and `imageB` can be either Strings (file path on node.js,
      // public url on Browsers) or Buffers
      imageA: '/path/to/imageA',
      imageB: fs.readFileSync('/path/to/imageB'),
    
      // Needs to be one of Rembrandt.THRESHOLD_PERCENT or Rembrandt.THRESHOLD_PIXELS
      thresholdType: Rembrandt.THRESHOLD_PERCENT,
    
      // The maximum threshold (0...1 for THRESHOLD_PERCENT, pixel count for THRESHOLD_PIXELS
      maxThreshold: 0.01,
    
      // Maximum color delta (0...255):
      maxDelta: 20,
    
      // Maximum surrounding pixel offset
      maxOffset: 0,
    
      renderComposition: true, // Should Rembrandt render a composition image?
      compositionMaskColor: Rembrandt.Color.RED // Color of unmatched pixels
    })
    
    // Run the comparison
    rembrandt.compare()
      .then(function (result) {
        console.log('Passed:', result.passed)
        console.log('Difference:', (result.threshold * 100).toFixed(2), '%')
        console.log('Composition image buffer:', result.compositionImage)
    
        // Note that `compositionImage` is an Image when Rembrandt.js is run in the browser environment
      })
      .catch((e) => {
        console.error(e)
      })
    

    如您所见,伦勃朗还允许您引入阈值,这可能为处理颜色变化提供一些支持。

    【讨论】:

      【解决方案2】:

      如果您正在寻找两个图像之间的简单“距离”,dhash-image 模块将实现dHash 算法。

      它转换为灰度(忽略颜色)并处理不同尺寸的图像,因此很好地满足了这些需求。

      我一直在使用 dHash 对图像处理库进行自动回归测试。如果您需要这种相对精度,它会非常快,但我希望 OpenCV 的 SIFT/SURF 功能能够提供更高的绝对精度。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-14
        • 2013-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-11
        • 2012-07-14
        • 1970-01-01
        相关资源
        最近更新 更多