Yet Another Assertion failed (scn == 3 || scn == 4)
I am aware that this usually means I have an empty matrix, but when I output mat.rows and mat.cols, I get the expected image dimensions (200x200). I originally had the cv::imread()
function but I replaced it with QImage
, with still no effect. Bad file paths have also been tested for. Relevant code:
void FaceDetector::loadCSV(const cv::String& filePath, std::vector<cv::Mat>& images, std::vector<int>& labels, char separator) {
std::ifstream file(filePath.c_str(), std::ifstream::in);
if(!file) {
qDebug() << "Error: " << std::strerror(errno);
}
std::string line, path, classlabel;
while(std::getline(file, line)) {
std::stringstream liness(line);
std::getline(liness, path, separator);
std::getline(liness, classlabel);
if(!path.empty() && !classlabel.empty()) {
QImage img(QString::fromStdString(path));
cv::Mat m = qImagetoMat(img);
if (m.data == NULL | m.empty()) {
qDebug() << "Empty matrix";
}
qDebug() << m.cols << m.rows;
cv::cvtColor(m, m, CV_RGB2GRAY);
images.push_back(m);
labels.push_back(atoi(classlabel.c_str()));
}
}
qDebug() << "loaded csv";
}
//Convert QImage to cv::Mat (probably the trouble area?)
cv::Mat FaceDetector::qImagetoMat(QImage &img, int format) {
return cv::Mat(img.height(), img.width(), format, img.bits(), img.bytesPerLine());
}