Mat和written image是不一样的

Mat and written image are not same

本文关键字:不一样 image written Mat      更新时间:2023-10-16

我在程序中创建了一个Mat变量,但是当我将它直接传递给函数时,它与我使用imwrite编写它并再次使用imread在函数中读取它相比具有不同的方式。

为什么会这样?
对我来说,正确的形式是当我写入和读取图像时,但在这种情况下,程序必须访问硬2次,这会使程序变慢。我如何防止它并直接使用我的Mat变量?

如果您不需要使用任何其他应用程序查看您的图像,您可以使用OpenCV的内置FileStorage实现将Mat对象写入XML/YAML类。下面是一个示例:-

//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