Closed dev-bun closed 1 year ago
That's not much detail to go on. My guess is that the image is not converted correctly to an array for some reason but hard to tell without more info
const browser = await puppeteer.launch({
args:[
" --no-sandbox"
]
});
const page = await browser.newPage();
await page.goto(`https://${domain}`);
await page.screenshot({ path: `screenshots/${domain.replace(".", "-")}.png` });
const img1 = loadImage(`known/hype.png`);
const img2 = loadImage(`/screenshots/${domain.replace(".", "-")}.png`);
const { mssim, performance } = ssim(img1, img2);
console.log(`SSIM: ${mssim} (${performance}ms)`);
this is my code - its takes a screenshot of a domain then compares it to a known scam domain screenshot
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
My code is also throwing same error.
const ssim = require("ssim.js");
const { loadImage } = require("canvas");
try{
const img1 = loadImage("./WIN_20221017_16_49_44_Pro.jpg");
const img2 = loadImage("./WIN_20221017_16_50_34_Pro.jpg");
const result = ssim.ssim(img1, img2);
console.log('SSIM: ${result.mssim}, \n Time to compute : (${performance}ms')
}
catch(err) {
console.error('Error on SSIM : ', err)
}
Error generating SSIM RangeError: Invalid array length
at Object.rgb2grayInteger (C:\Users\Paavan Reddy\Desktop\CJPL\NestJS\biometric\node_modules\ssim.js\dist\matlab\rgb2gray.js:48:17)
at toGrayScale (C:\Users\Paavan Reddy\Desktop\CJPL\NestJS\biometric\node_modules\ssim.js\dist\index.js:69:26)
at Object.ssim (C:\Users\Paavan Reddy\Desktop\CJPL\NestJS\biometric\node_modules\ssim.js\dist\index.js:91:39)
at Object.
If it fails there it's failing to get the width or height (or both). I would log the data before passing it to ssim to make sure it has the right shape
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Workaround:
const { ssim } = require("ssim.js");
const { createCanvas, loadImage } = require("canvas");
async function generateImageData(file) {
const image = await loadImage(file);
const canvas = createCanvas(image.width, image.height);
const context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
return {
data: context.getImageData(0, 0, image.width, image.height).data,
width: image.width,
height: image.height
};
}
async function init() {
console.log(ssim(await generateImageData("C:/img1.jpg"), await generateImageData("C:/img2.jpg")));
}
init();