首页 文章

opencv节点ImageSimilarity错误batchDistance

提问于
浏览
0

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

OpenCV错误:断言失败(类型== src2.type()&& src1.cols == src2.cols &&(type == CV_32F || type == CV_8U))batchDistance,file / build / opencv-SviWsf / opencv -2.4.9.1 dfsg / modules / core / src / stat.cpp,第2473行终止在抛出'cv :: Exception'的实例后调用what():/ build / opencv-ScanWsf / opencv-2.4.9.1 dfsg / modules /core/src/stat.cpp:2473:错误:(-215)type == src2.type()&& src1.cols == src2.cols &&(type == CV_32F || type == CV_8U)函数batchDistance

这是我的代码示例:

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

                    });
                }
            });
        });

我想捕捉错误或检测哪些照片导致错误 .

提前致谢!

1 回答

  • 0

    最后我发现了以下修复:

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

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

相关问题