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 && func != 0) in cv::countNo
nZero, file C:uilds2_4_PackSlave-win32-vc12-sharedopencvmodulescoresrcst
at.cpp, line 549
Can somebody please point out the mistake?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…