OpenCVSharp 小知识 Mat的序列化和反序列化

最近太忙,简单写写.

OpenCVSharp提供了Mat的序列化和反序列化方法-----FileStorage类,下面简单演示用法,

 

            Mat src = new Mat(3, 3, MatType.CV_8UC1);
            Cv2.Randu(src, Scalar.All(0d), Scalar.All(255d));

            Console.WriteLine("序列化:" ); 
            Console.WriteLine(Cv2.Format(src, FormatType.Python));
            FileStorage storagewrite = new FileStorage("file.xml", FileStorage.Mode.Write);
            storagewrite.Write("src", src);
            storagewrite.Release();


            Console.WriteLine("反序列化:");
            FileStorage storageread = new FileStorage("file.xml", FileStorage.Mode.Read);
            Mat loadsrc = storageread["src"].ToMat();
            Console.WriteLine(Cv2.Format(loadsrc, FormatType.Python));
            Console.ReadKey();

 

你可能感兴趣的:(OpenCVSharp)