forked from shimat/opencvsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialization.cs
More file actions
48 lines (41 loc) · 1.7 KB
/
Copy pathSerialization.cs
File metadata and controls
48 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using OpenCvSharp;
using SampleBase;
namespace CStyleSamplesCS
{
/// <summary>
/// Binary Serialization
/// </summary>
class Serialization
{
public Serialization()
{
const string FileName = "serialization.dat";
IplImage imgWrite = new IplImage(FilePath.Image.Fruits, LoadMode.Color);
IplImage imgRead;
using (FileStream fs = new FileStream(FileName, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, imgWrite);
}
FileInfo info = new FileInfo(FileName);
Console.WriteLine("{0} filesize:{1}bytes", info.Name, info.Length);
using (FileStream fs = new FileStream(FileName, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
imgRead = (IplImage)bf.Deserialize(fs);
}
Console.WriteLine("Source: width:{0} height:{1} depth:{2} channels:{3} imagesize:{4}",
imgWrite.Width, imgWrite.Height, imgWrite.Depth, imgWrite.NChannels, imgWrite.ImageSize);
Console.WriteLine("Deserialize: width:{0} height:{1} depth:{2} channels:{3} imagesize:{4}",
imgRead.Width, imgRead.Height, imgRead.Depth, imgRead.NChannels, imgRead.ImageSize);
using (new CvWindow("Source Image", imgWrite))
using (new CvWindow("Deserialized Image", imgRead))
{
Cv.WaitKey();
}
}
}
}