Hi! I have this exception
OpenCV Error: Assertion failed (src.channels() == 1 && func != 0) in countNonZero
and I don't understan why. I use it in this function:
bool compare_images(string file1, string file2) {
cout << "comapre_images > file1: "<<file1<<", file2: "<<file2<<endl;
cv::Mat m1 = cv::imread(file1);
cv::Mat m2 = cv::imread(file2);
if(m1.empty() || m2.empty()) {
cout << "WARNING: one of the two file is empty" << endl;
return false;
}
if (m1.cols != m2.cols || m1.rows != m2.rows || m1.dims != m2.dims) {
cout << "WARNING: the two images differs on size" << endl;
return false;
}
cv::Mat diff;
cv::compare(m1, m2, diff, cv::CMP_NE);
int nz = cv::countNonZero(diff);
std::cout << "comparing " << file1 << " and " << file2
<< " the diff pixels are:" << nz;
return nz==0;
}