2017-08-06 289 views
0

我試圖找到圖像中最大的斑點,並根據鏈接的plist文件對其進行分類。我正在使用最新版本的OpenCV for iOS,並且我已經查看了幾個相關的問題,但目前爲止還沒有涉及到iOS。當我運行這個OpenCV錯誤:iOS上的斷言失敗

OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in batchDistance, file /Users/admin/Desktop/OpenCV/modules/core/src/stat.cpp, line 4000

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/admin/Desktop/OpenCV/modules/core/src/stat.cpp:4000: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function batchDistance

- (IBAction)CaptureButton:(id)sender 
    { 
     // Find the biggest blob. 
     int biggestBlobIndex = 0; 
     for (int i = 0, biggestBlobArea = 0; i < detectedBlobs.size(); i++) 
     { 
      Blob &detectedBlob = detectedBlobs[i]; 
      int blobArea = detectedBlob.getWidth() * detectedBlob.getHeight(); 
      if (blobArea > biggestBlobArea) 
      { 
       biggestBlobIndex = i; 
       biggestBlobArea = blobArea; 
      } 
     } 

     Blob &biggestBlob = detectedBlobs[biggestBlobIndex]; 

     // Classify the blob. 
     blobClassifier->classify(biggestBlob); // the error occurs here 
    } 

是我打電話在最後一行出現在另一個文件中聲明的classify

我得到這個錯誤

void classify(Blob &detectedBlob) const; 

這是stat.cpp的相關代碼:

Mat src1 = _src1.getMat(), src2 = _src2.getMat(), mask = _mask.getMat(); 
int type = src1.type(); 

CV_Assert(type == src2.type() && src1.cols == src2.cols && 
      (type == CV_32F || type == CV_8U)); // this is line 4000 

這裏有什麼問題?

+0

斷言失敗的一個列出的屬性。找出哪一個,爲什麼並解決這個問題。你知道調試器是什麼嗎? – Piglet

+0

@Piglet是的,但我不確定如何找到導致錯誤的屬性。 – fi12

+0

您可以在stat.cpp中爲行3934添加一個斷點並查看這些值。 – Piglet

回答

1

我不知道cv :: Mat對象如何看待目標c,但是您需要確保與分類器一起使用的圖像的所有維度,通道數量和深度都是統一的。當您向分類器輸入訓練圖像時,可能以前有一個步驟。也許其中一個與您試圖分類的墊子不兼容。

如果您自己編譯並在CMake中設置調試版本,您可以嘗試使用opencv進行調試。

+0

所以這個問題是由於我所有的訓練圖像都是不同的維度造成的? – fi12

+0

有沒有一種方法來保持不同維度的圖像,並仍然具有應用程序功能? – fi12

+0

該問題可能是由於您的圖像具有不同的尺寸。至於第二個問題,您可以嘗試裁剪圖像或填充缺失的空間以獲得正確的尺寸。或者問另一個關於分類非均勻尺寸圖像集的問題。 – morynicz

相關問題