Mat and written image are not same

104 views Asked by At

I create a Mat variable in my program, but when I pass it directly to a function, it has different manner compare to when I write it with imwrite and again read it in function with imread.

Why this is happening?
The correct form for me is when I write and read the image, but in this case program have to access to hard 2 times and it makes the program slow.
How I can prevent it and use my Mat variable directly?

1

There are 1 answers

0
The Nomadic Coder On

If you don't need to view your Image using any other application, you could write your Mat object onto an XML/YAML class using OpenCV's built in FileStorage Implementation. Following is a sample :-

//Writing
cv::FileStorage fs;
fs.open(filename, cv::FileStorage::WRITE);
fs<<"MyImage"<<Image1;

//Reading
fs.open(filename, cv::FileStorage::READ);
fs["MyImage"]>>Image1;

fs.release(); //Very Important