1

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?

4
  • assertion failed for one of the listed properties. find out which one, why and fix that. you know what a debugger is? Commented Aug 7, 2017 at 7:45
  • @Piglet Yes, but I'm unsure as to how to find the property that is causing the error. Commented Aug 7, 2017 at 12:25
  • You could add a break point befor line 3934 in stat.cpp and see the values. Commented Aug 7, 2017 at 12:39
  • @Piglet The issue is that stat.cpp isn't in this Xcode project; it's in the same directory as the OpenCV framework is. When I place a breakpoint on the relevant line, nothing happens, because they're not in the same project together. Commented Aug 8, 2017 at 2:19

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

So the issue is caused because all of my training images are different dimensions?
Is there a way to keep training images of different dimensions and still have the application function?
The issue MAY be caused by Your images having differnet dimensions. As for the second question, You could just try either cropping the images or filling the missing space to get the correct dimensions. Or ask another question about classifying non uniform dimensions image sets.
do you know how to classify a set of non uniform dimension images?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.