Ich bin neu zu openCV und nicht wirklich mit vielen OpenCV C++ Apis vertraut. Ich erstelle eine Datenbank und extrahiere die LBP-Funktionen aus den Bildern & schreibe die Funktionen in eine XML-Datei, versuche ich nicht, die cv :: Mat für mehr als 50 Bilder zu halten, so dass ich nicht Speicher Out-of-Bounds-Ausnahme. Also rufe ich eine sich wiederholende Funktion "create_xml()" auf. Ich bekomme immer den Fehler malloc: *** error for object 0x1030d6008: incorrect checksum for freed object - object was probably modified after being freed. *** set a breakpoint in malloc_error_break to debug
Ein nicht wiederkehrender malloc_error_break in OpenCV
Ein weiterer Punkt ist, dass dieser Fehler nicht wiederholt wird, ich bekomme es an verschiedenen Stellen im Programmcode. Ich verstehe, dass ich meine Streichungen überprüfen muss, also habe ich alle meine Streichungen aufgehoben. Trotzdem bekomme ich den Fehler. Ich habe auch nach einer falschen Speicherzuweisung überprüft.
Ich habe mir thisthis angesehen und this habe immer noch keine Ahnung wo ich weiter vorgehen soll, mein Fehlerstack und der Programmcode sind unten angehängt, bitte helft mir weiter. Ich habe versucht, für malloc_error_break
Suche hier, aber keiner scheint mein Problem zu lösen, damit einen neuen Beitrag
for(int index =0;index<sub_Folders.size();index++)
{
cv::Mat feats;
string s = sub_Folders[index]+"/";
feats = create_xml(TRAINING_PATH.c_str(),s);
//writing the features in the training file storage
//fs_training<<"features"<<feats;
fs_training <<"features"<< "[";
cv::Size siz = feats.size();
for(int index =0;index<siz.width;index++)
{
fs_training<<feats.at<double>(index)<<" ";
}
fs_training<<"]";
//writing the label in the file sorage
//fs_labels<<"label"<<subfolder;
fs_labels<<"labels"<<"[";
fs_labels<<s<<"]";
}
cv::Mat create_xml(const char* TRAINING_PATH, string subfolder)
{
//now reading the individual images and saving it in the MAT to be fed in as training data
std::vector<cv::String> fn; // to store the file names in each sub folder
std::vector<cv::Mat> imgMat;
string s=TRAINING_PATH+subfolder;
cv::glob(s,fn,false);
for(int j=0;j<fn.size();j++)
{
cout<<"Sub Fldr path "<<s<<endl;
cout<<"Processing Image "<<fn[j]<<endl;
cout<<fn[j].substr(s.size())<<endl;
//string temp =fn[j].substr(s.size());
string temp = fn[j].substr(fn[j].size()-4);
cv::Mat image = cv::imread(fn[j]);
//if(temp.compare("/.")!=0 && temp.compare("/..")!=0 && temp.compare("/.DS_Store")!=0 && temp.compare("/feature.bin")!=0 && temp.compare("/info.txt")!=0 && temp.compare("/filelist_LBP.txt")!=0)
if(temp.compare(".jpg") == 0)
{
if(!image.data)
{
cerr<<"Problem Loading image!!!"<<endl;
exit(0);
}
if(image.data)
{
// collect all the image into the Mat imgMat to avarage it out.
cv::resize(image,image,cv::Size(160,160));
imgMat.push_back(image);
}
}
}
//average all the images from the subfolder ie., all the images from the folder aamir khan
cv::Mat averageMat = cv::Mat::zeros(160, 160,CV_32FC1);
cout<<"calculating the avg "<<imgMat.size()<<endl;
for(int index=0; index<imgMat.size();index++)
{
for(int row=0;row<160;row++)
{
for(int col=0;col<160;col++)
{
averageMat.at<double>(col,row) = averageMat.at<double>(col,row) + imgMat[index].at<double>(col,row);
}
}
}
cout<<"finished adding"<<endl; // for testing remove it
for(int row=0;row<160;row++)
{
for(int col=0;col<160;col++)
{
averageMat.at<double>(col,row) = averageMat.at<double>(col,row)/imgMat.size();
}
}
cout<<"finished dividing"<<endl; // for testing remove this
std::vector<cv::Mat>().swap(imgMat);
cout<<"released imgMat"<<endl;
//cv::Mat averageMat_vector; //-> vector shaped to store as rows in feature vector Mat
cv::Mat feats; // -> to store the feature extacted from the average image in Mat format
cout<<"finished initializing the Mat"<<endl;
// now to extract features from the avg image
lbp::OLBP(averageMat,feats); //-> extracting the LBP features
lbp::histogram(feats,feats,256);//-> converting it into a histogram -> leniar array
cout<<"finished extracting features"<<endl;
return feats;
}