How to write a Float Mat to a file in OpenCV

后端 未结 5 2062
一个人的身影
一个人的身影 2020-12-01 09:09

I have a matrix

Mat B(480,640,CV_32FC1);

containing floating values..I want to write this matrix to a file which could be opened in notepad or M

5条回答
  •  温柔的废话
    2020-12-01 09:54

    use write binary :

    FILE* FP = fopen("D.bin","wb");
        int sizeImg[2] = { D.cols , D.rows };
        fwrite(sizeImg, 2, sizeof(int), FP);
        fwrite(D.data, D.cols * D.rows, sizeof(float), FP);
        fclose(FP);
    

    then you can read in in matlab read size and then reshape (type=single)

    fp=fopen(fname);
    data=fread(fp,2,'int');
    width = data(1); height = data(2);
    B = fread(fp,Inf,type);
    
    imageOut = reshape(B,[width,height])';
    
    fclose(fp);
    

提交回复
热议问题