Ask Your Question
0

iOS - Xcode - OpenCV - findContours error

asked 2017-09-23 04:16:08 -0600

Scherady gravatar image

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-09-26 23:56:52 -0600

Scherady gravatar image

Solved by changing Point to cv:Point in

 std::vector<std::vector<cv:Point> > contours;
edit flag offensive delete link more
0

answered 2017-09-23 09:07:14 -0600

matman gravatar image

Your srcImage type is not correct. Make sure it is single channel (which should be) and it's depth is CV_8U.

edit flag offensive delete link more

Comments

is

cvtColor( srcImage, srcImage, CV_BGR2GRAY );

not making srcImage single channel ?

adding

srcImage.convertTo(srcImage, CV_8U);

did not help :(

Scherady gravatar imageScherady ( 2017-09-23 10:08:37 -0600 )edit

Can you check

CV_Assert(srcImage.type() == CV_8UC1);

before findContours and are you sure cvtColor isn't throwing that exception?

matman gravatar imagematman ( 2017-09-23 10:18:31 -0600 )edit

No error is thrown before findContours and adding CV_Assert(srcImage.type() == CV_8UC1); before findContours did not help neither

Scherady gravatar imageScherady ( 2017-09-23 11:02:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-09-23 04:16:08 -0600

Seen: 1,101 times

Last updated: Sep 26 '17