Ask Your Question
0

Yet Another Assertion failed (scn == 3 || scn == 4)

asked 2016-06-08 13:17:13 -0500

htmlboss gravatar image

updated 2016-06-08 13:17:48 -0500

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());
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-08 20:57:10 -0500

Tetragramm gravatar image

scn typically means "source channels". So it's looking for a source image with 3 or 4 channels. You have the line RGB2GRAY there, which takes it from 3 or 4 to 1 channel. I'm guessing your error is in the cvtColor function. Can't help you past that though. Is your input image grayscale?

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-06-08 13:17:13 -0500

Seen: 321 times

Last updated: Jun 08 '16