【问题标题】:Qt program exited with code -1073741819Qt 程序退出,代码为 -1073741819
【发布时间】:2013-01-25 22:18:14
【问题描述】:

我正在使用 Windows 7 中的 Qt 和 Opencv 进行基于人脸识别的项目。我现在遇到了一个真正的死胡同...我需要使用一些图像来训练人脸识别器...但是每当我注释掉train 语句,程序运行良好,但没有放弃我的目的......

void Dialog::on_btnAdd_2_clicked()
{
    tmrTimer->stop();

    dir=QDir(directory);
    QFileInfoList files;
    QFileInfo file;
    QString filen;


    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    files=dir.entryInfoList();
    int nofiles;
    nofiles=files.size();
    for(int i=0;i<nofiles;i++)
    {
        file=files.at(i);
        filen=file.absoluteFilePath();


        std::string fname = filen.toStdString();

        filen=file.baseName();
        std::string filename=filen.toStdString();

        char* path = new char [fname.size()+1];
        char name[10];

        strcpy(name,filename.c_str());
        strcpy( path, fname.c_str() );

        name[1]='\0';

        ui->boxConsole->appendPlainText(path);
        ui->boxConsole->appendPlainText(name);

        cv::Mat temp=cv::imread(path,-1);
        newImages.push_back(temp);
        newLabels.push_back(atoi(name));
    }


    ui->boxConsole->appendPlainText("Training Started....!!");

    cv::Ptr<cv::FaceRecognizer> model = cv::createEigenFaceRecognizer();

    model->train(newImages,newLabels);   ///training statement

    //strcat(home,"\\data.xml");


    //model->save(home);


    ui->boxConsole->appendPlainText("Training Completed!!");
    tmrTimer->start();
}

当我运行项目并单击启动上述功能的按钮时,进程崩溃说...

Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: QtTracker3.exe
  Application Version:  0.0.0.0
  Application Timestamp:    5101dde0
  Fault Module Name:    libopencv_core242.dll
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp:   50da6896
  Exception Code:   c0000005
  Exception Offset: 000a38f0
  OS Version:   6.1.7600.2.3.0.256.1
  Locale ID:    1033
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

我根据建议修改了代码如下...然后又遇到了另一个问题...

void Dialog::on_btnAdd_2_clicked()
{
    tmrTimer->stop();

    dir=QDir(directory);
    QFileInfoList files;
    QFileInfo file;
    QString filen;

    char name[10];
    int i,j;
    std::string str;


    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    files=dir.entryInfoList();
    int nofiles;
    nofiles=files.size();

    for(i=0;i<nofiles;i++)
        {
            file=files.at(i);
            filen=file.baseName();
            std::string filename=filen.toStdString();
            strcpy(name,filename.c_str());

            for(j=0;name[j]!='-';j++);
            name[j]='\0';

            filen=file.absoluteFilePath();
            str=filen.toStdString();

            cv::Mat offimage=cv::imread(str.c_str(),-1);

            cv::namedWindow("face",WINDOW_AUTOSIZE);     //show retrieved image in a window
            cv::imshow("face",offimage);
            cvvWaitKey(1000);

            newImages.push_back(offimage);
            newLabels.push_back(atoi(name));


        }

我删除了 for 循环中使用的指针,但同样的问题仍然存在......

我还发现 qt creator 在其问题选项卡中报告了一个问题:

:-1: warning: auto-importing has been activated without --enable-auto-import specified on the command line.

【问题讨论】:

    标签: qt opencv


    【解决方案1】:

    当您的代码崩溃时,请使用调试器找出它崩溃的位置。如果您不明白原因,请在问题中添加回溯。

    我假设您的崩溃是在循环文件时处理文件名。 您使用 char* 而不是 std::string 或 QString 打开了多罐蠕虫,但操作不正确。

    这一次是非常不安全且不安全的(缓冲区溢出):

        char name[10];
        ...
        strcpy(name,filename.c_str());
    

    如果文件名超过 9,则行为未定义(很可能会崩溃)。

    你也泄漏了内存,因为这个分配永远不会被释放:char* path = new char [fname.size()+1];

    所以我强烈建议使用 QString 而不是摆弄 char*。如果您需要将 char* 传递给 OpenCV,您可以这样做:

    const QByteArray ba = filename.toLatin1(); //or toUtf8(), toLocal8Bit(), depending on the encoding you need
    ... functionTakingChar( ba.constData(), -1 ); // or .data(), if imread() takes a non-const char
    

    imread 需要一个 std::string,所以:

    ... imread( filename.toStdString(), -1 );
    

    【讨论】:

    • 我检查了其他所有内容,但导致错误的语句是 model->train() 调用...我已将文件命名为尽可能短....我需要使用图像对其进行训练从指定路径....
    • 我还创建了要在 gui 中提供的显示框中打印的名称,以便我可以确保标签字段没有错....感谢您的建议 :-)
    • 我已经按照你所说的进行了更改...现在它显示了一些其他错误:传递给 C 运行时函数的无效参数。传递给 C 运行时函数的参数无效。 OpenCV 错误:图像步骤错误(矩阵不连续,因此无法更改其行数)在 reshape,文件 C:\opencv\modules\core\src\matrix.cpp,第 801 行终止后调用'cv::Exception' 的实例 what(): C:\opencv\modules\core\src\matrix.cpp:801: error: (-13) 矩阵不连续,因此它的行数不能改变在函数中重塑
    • 如何调用imread()?我看到它需要一个 std::string,所以我扩展了答案。否则尝试在 throw 处设置一个捕获点,以查看引发异常的 bactrace。
    • 我刚刚修改了函数并更新了问题。现在它显示错误:OpenCV 错误:图像步骤错误(矩阵不连续,因此其行数不能改变)在重塑,文件 C:\opencv\modules\core\src\matrix.cpp,第 801 行......我确定输入图像的尺寸为 80*80,,,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2013-08-17
    • 1970-01-01
    • 2021-09-10
    • 2015-02-18
    • 2016-09-11
    相关资源
    最近更新 更多