分段故障核心转储 [英] Segmentation fault core dumped

查看:215
本文介绍了分段故障核心转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从c ++创建一个json文件。使用的代码如下:

I am trying to create a json file from c++. The used code is the following:

    Mat projected = eigenfacesExtraction(fileName);

    ofstream myfile;
    myfile.open ("detection.json");
    myfile << "{\n";
    myfile << "\t \"meta\":{\n";
    myfile << "\t \"duration\":\""<<duration<<"\",\n";  
    myfile << "\t \"fileName\":\""<<fileName<<"\"\n";
    myfile << "},\n";

    myfile << "\t \"num_of_people\":\""<< faces.size()<<"\",\n";
    myfile << "\t \"faces\":[\n";

    myfile << "\t \"projected\":[" << projected.size <<"] ,\n";

    for(int i=0; i<faces.size(); i++){

        if(!faces.empty()){ 
            if(i!= faces.size()-1){
            myfile << "\t \"coord\":\" \t[" << faces[i].x << ", "<<faces[i].y<< ", "<<      faces[i].width << ", "<<faces[i].height<<"],\n";
            myfile << "\t \"descr\":\" \t[" << projected.at<double>(0,1) << ", "<<projected.at<double>(0,2)<< ", "<<        projected.at<double>(0,3) << ", "<<projected.at<double>(0,4)<<"],\n";
            }
            else myfile << "\t \"coord\":\" \t[" << faces[i].x << ", "<<faces[i].y<< ", "<<     faces[i].width << ", "<<faces[i].height<<"]\n";
                 myfile << "\t \"descr\":\" \t[" << projected.at<double>(0,1) << ", "<<projected.at<double>(0,2)<< ", "<<       projected.at<double>(0,3)<< ", "<<projected.at<double>(0,4)<<"],\n";
        }
    }

    myfile << "]\n";
    myfile << "}";
    myfile.close();

    cout<< "Detection process exits...."<<endl;
    //imwrite( "/opencvAssets/results/"+fileName, image );
    imwrite("outputCapture.jpeg", image);
    //waitKey(0);
    //imshow("cropped image", croppedFaceImage);

我的程序工作正常,json文件正确存储cout打印消息,但我收到跟随消息Segmentation fault(core dumped)。当我注释掉iwrite命令既不json也不cout工作,我又收到相同的消息。这里的事情是什么? eigenFacesExtraction函数(可能会导致问题)如下:

My program works fine, json file is stored properly also cout prints the message, but I am receiving the following message "Segmentation fault (core dumped)". When I comment out iwrite command neither json nor cout work and I am receiving again the same message. What is the matter here?? The eigenFacesExtraction function (which may cause the problems) is the following:

 Mat Detection::eigenfacesExtraction(string fileName){

    Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
    model->load("eigenfaces.yml"); // Load eigenfaces parameters
    Mat eigenvalues = model->getMat("eigenvalues"); // Eigen values of PCA
    Mat convMat = model->getMat("eigenvectors"); //Convariance matrix which contains eigenvectors
    Mat mean = model->getMat("mean"); // Mean value

    convMat.convertTo(convMat, CV_32F);
    mean.convertTo(mean, CV_32F);

    string path = fileName;

    Mat sample ,pca_ed_sample, resizedSample;
    sample = imread(path, CV_LOAD_IMAGE_GRAYSCALE);

    sample.convertTo(sample, CV_32F);
    resize(sample,resizedSample,Size(60,60),0,0,INTER_LINEAR);
    Mat nu =  resizedSample.reshape(1,3600).t();
    pca_ed_sample = (nu-mean)*(convMat);

    return pca_ed_sample;

}


推荐答案

发生在我们试图改变只读可读内存或当我们试图从你的程序边界访问内存。将其放在调试器中,并进行彻底跟踪。有关更多信息,请参阅此stackoverflow问题

Segmentation fault occurs when we try to change only readable memory or when we try to access the memory out of your program boundaries. Place it in a debugger and trace it thoroughly. For more information chech this stackoverflow question

什么是分段错误?

这篇关于分段故障核心转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆