I have a custom structure:
struct custom_roi{
Mat roi;
int x;
int y;
};
I'm trying to save that structure to a binary file in c++. I'm using the following code:
ofstream wf;
wf.open("roi.dat", ios::out | ios::binary);
if (!wf) {
cout << "Cannot open file!" << endl;
return 1;
}
string image_path = "D:/images/pic1.jpg";
Mat LoadedImage;
LoadedImage = imread(image_path, IMREAD_COLOR);
FileStorage fs;
custom_roi wsf;
Rect Rec(100, 100, 400, 400);
Mat roi = LoadedImage(Rec);
wsf.x = 100;
wsf.y = 100;
roi.copyTo(wsf.roi);
wf.write((char*)&wsf, sizeof(custom_roi));
wf.close();
When I try to read the file back the x, y and the roi dimensions values are correct but there is a message saying "Error reading characters of string". What am I doing wrong? Your help will be really appreciated. Thank you.