下面是我尝试的代码:
String.prototype.hashCode = function(){
var hash = 0;
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
var arrayString= this[i].split("");
for(j=0;j<arrayString.length;j++){
char = arrayString.charCodeAt(j);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
}
return hash;
}
我建议使用https://github.com/peterbraden/node-opencv功能图像相似性例如,我确实从Google下载了两张图片。
apple.jpg,我将其复制并另存为apple2.jpg,我下载了3º图像并使用apple3.png重命名
const cv = require('opencv');
cv.readImage("apple.jpg", function(err, apple1) {
if (err) throw err;
cv.readImage("apple3.png", function(err, apple2) {
if (err) throw err;
cv.ImageSimilarity(apple1, apple2, function (err, dissimilarity) {
if (err) throw err;
console.log(dissimilarity);
});
});
});
此案例的结果是:72.48076923076923
const cv = require('opencv'); cv.readImage("apple.jpg", function(err, apple1) { if (err) throw err; cv.readImage("apple2.jpg", function(err, apple2) { if (err) throw err; cv.ImageSimilarity(apple1, apple2, function (err, dissimilarity) { if (err) throw err; console.log(dissimilarity); }); }); });
为此,是:0apple.jpg和apple2.jpg是完全相同的图像。