i am running a basic application using openCV for C++. I am attempting to split the image into rgb components using cvSplit() as below:
CvMat* mat;
//initialize mat
CvMat* b = cvCreateMat(mat->rows, mat->cols, CV_8UC1);
CvMat* g = cvCreateMat(mat->rows, mat->cols, CV_8UC1);
CvMat* r = cvCreateMat(mat->rows, mat->cols, CV_8UC1);
cvSplit(mat, b, g, r, NULL );
It builds just fine, but when I attempt to run it, I get the following error:
OpenCV Error: Assertion failed (i < src.channels()) in cvSplit, file /home/username/Downloads/OpenCV-2.4.0/modules/core/src/convert.cpp, line 1196
terminate called after throwing an instance of 'cv::Exception'
What does this error mean, and how can I solve the problem?
The IplImage you are using to create the Mat should be in color. You need three channels to be able to use
cvSplit. You can check this withIplImage->nChannelsin your debugger.