Node.js opencv节点图像相似性错误批处理距离

Node.js opencv节点图像相似性错误批处理距离,node.js,image,opencv,compare,Node.js,Image,Opencv,Compare,我试图开发一个函数来比较两个图像(相同大小),但有时我从opencv模块中得到以下错误 OpenCV错误:在batchDistance文件/build/OpenCV SviWsf/OpenCV-2.4.9.1+dfsg/modules/core/src/stat.cpp第2473行,断言失败(type==src2.type()&&src1.cols==src2.cols&(type==cv32f | | type==CV 8U)) 在引发“cv::Exception”的实例后调用terminat

我试图开发一个函数来比较两个图像(相同大小),但有时我从opencv模块中得到以下错误

OpenCV错误:在batchDistance文件/build/OpenCV SviWsf/OpenCV-2.4.9.1+dfsg/modules/core/src/stat.cpp第2473行,断言失败(type==src2.type()&&src1.cols==src2.cols&(type==cv32f | | type==CV 8U)) 在引发“cv::Exception”的实例后调用terminate 函数batchDistance中的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)

这是我的代码示例:

        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);
                            }
                        }

                    });
                }
            });
        });
if(basePhoto!=''&&secondPhoto!=''){
下载(url2,“路径/”+secondPhoto.id+“.jpg”,函数(错误,结果){
如果(错误){
控制台错误(“下载错误”,err);
拒绝(错误);
}
cv.readImage(结果、函数(错误、cfotob){
如果(错误){
错误(“错误图像-->”,错误);
拒绝(错误);
}
if(cfotob.empty()| | basePhoto.empty()){
拒绝(“照片不能为空”,空);
}否则{
cv.ImageSimilarity(basePhoto.matrix、cfotob、函数(err、相异性){
如果(错误){
拒绝(错误);
}否则{
if(相异度<25.00){
log(“这些图像是相等的”);
决心(正确);
}否则{
//不相上下
log(“此图像”+basePhoto.id+”不等于“+secondPhoto.id”);
决议(假);
}
}
});
}
});
});
我想捕捉错误或检测导致错误的照片


提前感谢!

最后,我找到了以下修复方法:

在调用cv.ImageSimilarity函数之前,我检查我的照片是否有颜色

  if (basePhoto.matrix.col().length && cfotob.col().length) {
        cv.ImageSimilarity(basePhoto.matrix, cfotob, function (err, dissimilarity) {
                  ....