I'm trying to develop a function to compare two images(same size) but sometimes I'm getting the following error from opencv module.
OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in batchDistance, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/core/src/stat.cpp, line 2473 terminate called after throwing an instance of 'cv::Exception' what(): /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/core/src/stat.cpp:2473: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function batchDistance
This is an example of my code:
if (basePhoto != '' && secondPhoto != '') {
download(url2, "path/" + secondPhoto.id + ".jpg", function (err, result) {
if (err) {
console.error("Error downloading", err);
reject(err);
}
cv.readImage(result, function (error, cfotob) {
if (error) {
console.error("Error image-->", error);
reject(error);
}
if (cfotob.empty() || basePhoto.empty()) {
reject("Photo cant be empty", null);
} else {
cv.ImageSimilarity(basePhoto.matrix, cfotob, function (err, dissimilarity) {
if (err) {
reject(err);
} else {
if (dissimilarity < 25.00) {
console.log("Those images are equal");
resolve(true);
} else {
//not equal
console.log("This image " + basePhoto.id + " is not equal to " + secondPhoto.id);
resolve(false);
}
}
});
}
});
});
I'd like to catch the error or detect which photos are causing the error.
Thanks in advance!