0

i'm beginning in c++ and i try to use xml in my code, this is my source code :

cv::FileStorage fs("facedata.xml", cv::FileStorage::WRITE);
cv::Mat mask = cv::Mat::zeros(8, 8, CV_32FC1); // all 0
mask(Rect(2,2,4,4)) = 1;
fs << "histo" <<mask;
CvMat * Mat=cvCreateMat(8,8,CV_32FC1);
cvZero(Mat);
fs.release();
cv::FileStorage fs2("facedata.xml", cv::FileStorage::READ);
CvScalar pix;
int K,L;
fs2 [ "histo" ]>> Mat;
for ( K=0;K<8;K++)
   for ( L=0;L<8;L++){
        pix=cvGet2D( Mat,K,L);
        cout<<(int) pix.val[0]<<endl;}

but Matdoes not return the content of histo, i need your help.

berak
  • 39,159
  • 9
  • 91
  • 89
David
  • 43
  • 7

1 Answers1

3

David, please avoid any c-api constructs in your opencv code.

anything, that wants a pointer, or starts with cv* should be left out !!

cv::FileStorage fs("facedata.xml", cv::FileStorage::WRITE);
cv::Mat mask = cv::Mat::zeros(8, 8, CV_32FC1); // all 0
mask(Rect(2,2,4,4)) = 1;
fs << "histo" <<mask;
fs.release();

//CvMat * Mat=cvCreateMat(8,8,CV_32FC1); // OUCH, NOO!
//cvZero(Mat);
cv::Mat m; // please do not call a variable 'Mat', since there's a class with same name already.

cv::FileStorage fs2("facedata.xml", cv::FileStorage::READ);
fs2 [ "histo" ]>> m;
cout<< m <<endl; // you can just dump a cv::Mat to stdout !
berak
  • 39,159
  • 9
  • 91
  • 89