-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuickCapture_X2.cs
198 lines (154 loc) · 6.12 KB
/
QuickCapture_X2.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if Halcon_Enable
using HalconDotNet;
#endif
#if OpenCV_Enable
using OpenCvSharp;
#endif
#if VisionPro_Enable
using Cognex.VisionPro;
#endif
using RVC_CSharp;
namespace RVC_CSharp
{
class Program
{
static void Main()
{
#region Step 0 , Start init system.
if (false == RVC_CSharp.System.Init() )
{
Console.WriteLine("Failed to init system.");
return;
}
else
{
Console.WriteLine("Successfully init system.");
}
#endregion
#region Step 1 , Find Device
// Method 1 , find Device By Sn . You can get device SN by RVC Manager.
// * Most Recommended Method .
//Device device = RVC_CSharp.System.FindDeviceBySN("12345678");
// Method 2 , find Device By Index .
// If you only have one camera, you can use this method.
Device device = RVC_CSharp.System.FindDeviceByIndex(0);
if (false == device.IsValid() || false == device.CheckCanConnected())
{
Console.WriteLine("Device Can not be Connected.\nPlease Check Connection.");
RVC_CSharp.System.Shutdown();
return;
}
// optional
// Print Device Info
DeviceInfo info = new DeviceInfo();
device.GetDeviceInfo(ref info);
info.Print();
#endregion
#region Step 2 , Open Camera
if (false == info.support_x2)
{
Console.WriteLine("Device Can not Support X2 .\nPlease Check Your Device.");
RVC_CSharp.System.Shutdown();
return;
}
X2 camera = RVC_CSharp.X2.Create(device);
camera.Open();
if (false == camera.IsValid()|| false == camera.IsOpen() )
{
Console.WriteLine($"Failed to open camera .Error code = { System.GetLastError() } ");
RVC_CSharp.System.Shutdown();
return;
}
#endregion
#region Step 3 , Capture
// Capture using the internal parameters of the camera.
// We suggest that you adjust the parameters in RVC Manager first.
bool ret = camera.Capture();
if (false == ret)
{
Console.WriteLine($"Failed to Capture .Error code = { System.GetLastError() } ");
camera.Close();
camera.Destroy();
RVC_CSharp.System.Shutdown();
return;
}
Image image = camera.GetImage(CameraID.CameraID_Left);
DepthMap depth = camera.GetDepthMap();
PointMap pointMap = camera.GetPointMap();
#endregion
#region Step 4 , Data Process
Directory.CreateDirectory($"./{info.name}-{info.sn}");
// 2D Image
string imageFile = $"./{info.name}-{info.sn}/Image.bmp";
Console.WriteLine($"Save Image,path = {imageFile}");
image.SaveImage(imageFile);
// Depth
string depthFile = $"./{info.name}-{info.sn}/Depth.tiff";
Console.WriteLine($"Save Depth,path = {depthFile}");
depth.SaveDepthMap(depthFile);
// Point Cloud
string pointCloudFile = $"./{info.name}-{info.sn}/PointCloud.ply";
Console.WriteLine($"Save PointMap,path = {pointCloudFile}");
pointMap.SavePlyBinary(pointCloudFile);
// Color Point Cloud
string colorPointCloudFile = $"./{info.name}-{info.sn}/ColorPointCloud.ply";
Console.WriteLine($"Save Color-PointMap,path = {colorPointCloudFile}");
pointMap.SaveColorPointCloud(image, colorPointCloudFile);
#if OpenCV_Enable
// OpencvExtension
Mat matImage = image.ToMat();
Mat matDepth = depth.ToMat();
Mat matPointCloud = pointMap.ToMat();
matImage.SaveImage($"./{info.name}-{info.sn}/OpencvImage.bmp");
Console.WriteLine($"Save Opencv Image,path = ./{info.name}-{info.sn}/OpencvImage.bmp");
#endif
#if Halcon_Enable
// HalconExtension,需要Lincese才能运行
try
{
HObject halconImage = image.ToHalcon();
HObject halconDepth = depth.ToHalcon();
HTuple halconPointCloud = pointMap.ToHalcon();
halconImage.SaveImage("bmp", $"./{info.name}-{info.sn}/HalconImage.bmp");
Console.WriteLine($"Save Halcon Image,path = ./{info.name}-{info.sn}/HalconImage.bmp");
halconDepth.SaveDepth("tiff", $"./{info.name}-{info.sn}/HalconDepth.tiff");
Console.WriteLine($"Save Halcon Depth,path = ./{info.name}-{info.sn}/HalconDepth.tiff");
halconPointCloud.SavePointCloud("om3", $"./{info.name}-{info.sn}/HalconPointCloud.om3");
Console.WriteLine($"Save Halcon PointMap,path = ./{info.name}-{info.sn}/HalconPointCloud.om3");
}
catch (Exception e)
{
Console.WriteLine(e);
}
#endif
#if VisionPro_Enable
// VisionProExtension,需要Lincese才能运行
try
{
CogImage16Range range = pointMap.ToVisionPro();
range.Save($"./{info.name}-{info.sn}/VisionProPointMap.idb");
Console.WriteLine($"Save VisionPro PointMap,path = ./{info.name}-{info.sn}/VisionProPointMap.idb");
}
catch (Exception e)
{
Console.WriteLine(e);
}
#endif
Console.WriteLine("Successfully Process Data .");
#endregion
#region Step 5 , Close And Release Device
camera.Close();
camera.Destroy();
RVC_CSharp.System.Shutdown();
Console.WriteLine("System close.");
#endregion
return;
}
}
}