Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

objective c - OpenCV error: Assertion failed on iOS

I'm trying to find the largest blob in an image and classify it according to a linked plist file. I'm using the latest version of OpenCV for iOS, and I've looked at several related questions, but none so far relate to iOS.

I'm getting this error:

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

when I run this:

- (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
  }

The classify that I'm calling in the last line there was declared in another file:

void classify(Blob &detectedBlob) const;

This is the relevant code from 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

What's the issue here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't know how do cv::Mat objects look in objective c, but You need to make sure that all the dimensions, channel number and depth of images used with the classifier are uniform. Probably there was a step previously when You fed the classifier with training images. Maybe one of them is not compatible with the mat that You are trying to classify.

You can try debugging with opencv if You compile it Yourself and set debug version in CMake.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...