node.js - Node.js 的图像比较库

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

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

最佳答案

嘿 RembrandtJS 可能正是您正在寻找的。 这是我们刚刚发布的一个轻量级库,它使用嵌入式 Node.JS 替换 Node Canvas 进行像素级图像比较。 它接受 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)
  })

正如您所看到的,Rembrandt 还允许您引入阈值,这可能为处理颜色变化提供一些支持。

关于node.js - Node.js 的图像比较库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28944397/

相关文章:

python - 将 HSV 掩码转换为一组点

node.js - Sequelize 中的多对一关联

node.js - 无法轻松地从测试运行器输出导航到 WebStorm 中的相关文件

node.js - 访问 Cloud Function 内的标签

c# - 将 JPEG 图像转换为字节数组 - COM 异常

java - 如何将Java中的图片保存到多个blob中?

javascript - jQuery/JS签名PNG图像编码?

node.js - 如何在 Promise 中使用循环

c++ - OpenCV 未初始化 USB 摄像头

python - 提取向上指向的车道线