2017-06-15 78 views
0

我試圖開發一個函數來比較兩個圖像(相同的大小),但有時我從opencv模塊得到以下錯誤。opencv節點ImageSimilarity錯誤batchDistance

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

這是我的代碼示例:

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

        }); 
       } 
      }); 
     }); 

我想捕獲錯誤或檢測這些照片引起的誤差。

在此先感謝!

回答

0

最後我發現下面的解決辦法:

調用cv.ImageSimilarity功能檢查我的照片有COLS之前。

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