title: Segmentation fault core dumped
body: <p>I am trying to create a json file  from c++. The used code is the following:</p>
  
  <pre><code>    Mat projected = eigenfacesExtraction(fileName);
  
      ofstream myfile;
      myfile.open ("detection.json");
      myfile &lt;&lt; "{\n";
      myfile &lt;&lt; "\t \"meta\":{\n";
      myfile &lt;&lt; "\t \"duration\":\""&lt;&lt;duration&lt;&lt;"\",\n";  
      myfile &lt;&lt; "\t \"fileName\":\""&lt;&lt;fileName&lt;&lt;"\"\n";
      myfile &lt;&lt; "},\n";
  
      myfile &lt;&lt; "\t \"num_of_people\":\""&lt;&lt; faces.size()&lt;&lt;"\",\n";
      myfile &lt;&lt; "\t \"faces\":[\n";
  
      myfile &lt;&lt; "\t \"projected\":[" &lt;&lt; projected.size &lt;&lt;"] ,\n";
  
      for(int i=0; i&lt;faces.size(); i++){
  
          if(!faces.empty()){ 
              if(i!= faces.size()-1){
              myfile &lt;&lt; "\t \"coord\":\" \t[" &lt;&lt; faces[i].x &lt;&lt; ", "&lt;&lt;faces[i].y&lt;&lt; ", "&lt;&lt;      faces[i].width &lt;&lt; ", "&lt;&lt;faces[i].height&lt;&lt;"],\n";
              myfile &lt;&lt; "\t \"descr\":\" \t[" &lt;&lt; projected.at&lt;double&gt;(0,1) &lt;&lt; ", "&lt;&lt;projected.at&lt;double&gt;(0,2)&lt;&lt; ", "&lt;&lt;        projected.at&lt;double&gt;(0,3) &lt;&lt; ", "&lt;&lt;projected.at&lt;double&gt;(0,4)&lt;&lt;"],\n";
              }
              else myfile &lt;&lt; "\t \"coord\":\" \t[" &lt;&lt; faces[i].x &lt;&lt; ", "&lt;&lt;faces[i].y&lt;&lt; ", "&lt;&lt;     faces[i].width &lt;&lt; ", "&lt;&lt;faces[i].height&lt;&lt;"]\n";
                   myfile &lt;&lt; "\t \"descr\":\" \t[" &lt;&lt; projected.at&lt;double&gt;(0,1) &lt;&lt; ", "&lt;&lt;projected.at&lt;double&gt;(0,2)&lt;&lt; ", "&lt;&lt;       projected.at&lt;double&gt;(0,3)&lt;&lt; ", "&lt;&lt;projected.at&lt;double&gt;(0,4)&lt;&lt;"],\n";
          }
      }
  
      myfile &lt;&lt; "]\n";
      myfile &lt;&lt; "}";
      myfile.close();
  
      cout&lt;&lt; "Detection process exits...."&lt;&lt;endl;
      //imwrite( "/opencvAssets/results/"+fileName, image );
      imwrite("outputCapture.jpeg", image);
      //waitKey(0);
      //imshow("cropped image", croppedFaceImage);
  </code></pre>
  
  <p>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:</p>
  
  <pre><code> Mat Detection::eigenfacesExtraction(string fileName){
  
      Ptr&lt;FaceRecognizer&gt; model = createEigenFaceRecognizer();
      model-&gt;load("eigenfaces.yml"); // Load eigenfaces parameters
      Mat eigenvalues = model-&gt;getMat("eigenvalues"); // Eigen values of PCA
      Mat convMat = model-&gt;getMat("eigenvectors"); //Convariance matrix which contains eigenvectors
      Mat mean = model-&gt;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;
  
  }
  </code></pre>