I am writing a code to read all the images in a folder and then write the information of the images in a binary all together. The problem is that when I use the function cv::imread
the field .data of the cv::MAT
always remains null, and when I'm going to write there is an error when accessing a null pointer.
I am using absolute paths obtained from a file .txt
in the following code:
void main(){
const unsigned int SizeImg = 1024 * 768 * sizeof(char);
std::ifstream file;
file.open("files.txt", std::ios::out);
std::string line;
std::string files[50];
std::string imagen;
std::ofstream Binary("Images.bin", std::ios::out | std::ios::binary);
int n = 0;
while (std::getline(file,line))
{
std::cout << line << '\n';
files[n] = line;
n++;
}
file.close();
for (int i = 0; i < n; i++){
imagen = files[i];
cv::Mat m = cv::imread(imagen, CV_LOAD_IMAGE_ANYCOLOR);
//cv::imshow("ventana", m);
cv::waitKey(0);
Binary.write((char*)m.data, SizeImg);
}
Binary.close();
}
I'm starting with OpenCV so there may be other things that are not very good either.