こんにちは、Mat オブジェクトをテキスト ファイルに書き込むことができます。次のように、
std::fstream outputFile;
    outputFile.open( "myFile.txt", std::ios::out ) ;
    outputFile << des_object.rows << std::endl;
    outputFile << des_object.cols << std::endl;
    for(int i=0; i<des_object.rows; i++)
    {
        for(int j=0; j<des_object.cols; j++)
        {
            outputFile << des_object.at<float>(i,j) << std::endl;
        }
    }
    outputFile.close( );
私のコードでは、最初の 2 行で、読み返すときに使用する行数と列数を出力しています。しかし、テキストファイルを読み取ってマットオブジェクトを再度作成することはできません。
以下は私が試したコードです。私のコードが正しいかどうかわかりません。
Mat des_object1;
    std::ifstream file("myFile.txt");
    std::string str; 
    int rows;
    int cols;
    int a = 0;
    while (std::getline(file, str))
    {
        int i = 0;
        int j = 0;
        if(a == 0){
            rows = std::stoi( str );
        }else if(a == 1){
            cols = std::stoi( str );
        }else{
            for(i; i< rows; i++)
            {
                for(j; j<cols; j++)
                {
                     des_object1.at<float>(i,j) = ::atof(str.c_str());
                     break;
                }
            }
        }
        ++a;
    }