Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

iOS - Xcode - OpenCV - findContours error

findContours causes the following error:

2017-09-22 16:50:05.396700+0200 OpenCVLiveCamera[7827:3041522] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-09-22 16:50:05.397011+0200 OpenCVLiveCamera[7827:3041522] [MC] Reading from public effective user settings. OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0)) in create, file /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/matrix.cpp, line 2601 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Volumes/build-storage/build/master_iOS-mac/opencv/modules/core/src/matrix.cpp:2601: error: (-215) mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0) in function create

Code:

void getContours(cv::Mat &srcImage){
cv::Mat dstImage = srcImage;
// Convert it to gray
cvtColor( srcImage, srcImage, CV_BGR2GRAY );
// Threshold
threshold(srcImage, srcImage, 192.0, 255.0, cv::THRESH_BINARY_INV);
// Find Contours to find chains of consecutive edge pixels
std::vector<std::vector<Point> > contours;
findContours(srcImage, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
// Draw contours on image
//....}

Please help. Thank you