countNonZero function gives an assertion error in openCV
I tried to get horizontal projection using countNonZero() function as below. Mat src = imread(INPUT_FILE, CV_LOAD_IMAGE_COLOR); Mat binaryImage = src.clone(); cvtColor(src, src, CV_BGR2GRAY); Mat horizontal = Mat::zeros(1,binaryImage.cols, CV_8UC1); for (int i = 0; i<binaryImage.cols; i++) { Mat roi = binaryImage(Rect(0, 0, 1, binaryImage.rows)); horizontal.at<int>(0,i) = countNonZero(roi); cout << "Col no:" << i << " >>" << horizontal.at<int>(0, i); } But an error is occured in the line of calling countonZero() function. Error is as follows. OpenCV Error: Assertion failed (src.channels() == 1