-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsvaf.cpp
More file actions
217 lines (177 loc) · 6.22 KB
/
svaf.cpp
File metadata and controls
217 lines (177 loc) · 6.22 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/***************************************************************************************
*** ***
*** Copyright (c) 2024, Lucid Vision Labs, Inc. ***
*** ***
*** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ***
*** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ***
*** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ***
*** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ***
*** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ***
*** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ***
*** SOFTWARE. ***
*** ***
***************************************************************************************/
#include "stdafx.h"
#include "ArenaApi.h"
#include "SaveApi.h"
#define TAB1 " "
// ImageProcessing: SplitChannels
// This example introduces splitting channels of an image and saving split images as JPEG images.
// =-=-=-=-=-=-=-=-=-
// =-=- SETTINGS =-=-
// =-=-=-=-=-=-=-=-=-
// pixel format
#define PIXEL_FORMAT BGR8
// file name
#define FILE_NAME "Images/SVAF/image"
#define JPG ".jpg"
// =-=-=-=-=-=-=-=-=-
// =-=- EXAMPLE -=-=-
// =-=-=-=-=-=-=-=-=-
// demonstrates saving an image
// (1) converts image to a displayable pixel format
// (2) prepares image parameters
// (3) prepares image writer
// (4) sets image writer to JPEG
// (5) saves image
// (6) destroys converted image
void SaveImage(Arena::IImage* pImage, const char* filename)
{
// convert image
std::cout << TAB1 << "Convert image to " << GetPixelFormatName(PIXEL_FORMAT) << "\n";
auto pConverted = Arena::ImageFactory::Convert(
pImage,
PIXEL_FORMAT);
// prepare image parameters
std::cout << TAB1 << "Prepare image parameters\n";
Save::ImageParams params(
pConverted->GetWidth(),
pConverted->GetHeight(),
pConverted->GetBitsPerPixel());
// prepare image writer
std::cout << TAB1 << "Prepare image writer\n";
Save::ImageWriter writer(
params,
filename);
// set image writer to JPEG
std::cout << TAB1 << "Set image writer to JPEG\n";
writer.SetJpeg(".jpg", 75, false, Save::EJpegSubsampling::NoSubsampling, false);
// save image
std::cout << TAB1 << "Save image to " << filename << "\n";
writer << pConverted->GetData();
// destroy converted image
Arena::ImageFactory::Destroy(pConverted);
}
// demonstrates splitting channels
// (1) calls SplitChannels to obtain images
// (2) save the images
void SplitChannelsAndSaveImages(Arena::IImage* pImage, const char* filename)
{
// Split channels
std::cout << TAB1 << "Split channels\n";
std::vector<Arena::IImage*> splitImages = Arena::ImageFactory::SplitChannels(pImage);
size_t num = 0;
for (auto pImage : splitImages)
{
// save image
std::string filenameWithNum = filename + std::to_string(num) + JPG;
SaveImage(pImage, filenameWithNum.c_str());
// destroy image
Arena::ImageFactory::Destroy(pImage);
num++;
}
}
// =-=-=-=-=-=-=-=-=-
// =- PREPARATION -=-
// =- & CLEAN UP =-=-
// =-=-=-=-=-=-=-=-=-
Arena::DeviceInfo SelectDevice(std::vector<Arena::DeviceInfo>& deviceInfos)
{
if (deviceInfos.size() == 1)
{
std::cout << "\n"
<< TAB1 << "Only one device detected: " << deviceInfos[0].ModelName() << TAB1 << deviceInfos[0].SerialNumber() << TAB1 << deviceInfos[0].IpAddressStr() << ".\n";
std::cout << TAB1 << "Automatically selecting this device.\n";
return deviceInfos[0];
}
std::cout << "\nSelect device:\n";
for (size_t i = 0; i < deviceInfos.size(); i++)
{
std::cout << TAB1 << i + 1 << ". " << deviceInfos[i].ModelName() << TAB1 << deviceInfos[i].SerialNumber() << TAB1 << deviceInfos[i].IpAddressStr() << "\n";
}
size_t selection = 0;
do
{
std::cout << TAB1 << "Make selection (1-" << deviceInfos.size() << "): ";
std::cin >> selection;
if (std::cin.fail())
{
std::cin.clear();
while (std::cin.get() != '\n')
;
std::cout << TAB1 << "Invalid input. Please enter a number.\n";
}
else if (selection <= 0 || selection > deviceInfos.size())
{
std::cout << TAB1 << "Invalid device selected. Please select a device in the range (1-" << deviceInfos.size() << ").\n";
}
} while (selection <= 0 || selection > deviceInfos.size());
return deviceInfos[selection - 1];
}
int main()
{
// flag to track when an exception has been thrown
bool exceptionThrown = false;
std::cout << "SVAF";
try
{
// prepare example
Arena::ISystem* pSystem = Arena::OpenSystem();
pSystem->UpdateDevices(100);
std::vector<Arena::DeviceInfo> devices = pSystem->GetDevices();
if (devices.size() == 0)
{
std::cout << "\nNo camera connected\nPress enter to complete\n";
std::getchar();
return 0;
}
Arena::DeviceInfo selectedDevice = SelectDevice(devices);
Arena::IDevice* pDevice = pSystem->CreateDevice(selectedDevice);
// enable stream auto negotiate packet size
Arena::SetNodeValue<bool>(pDevice->GetTLStreamNodeMap(), "StreamAutoNegotiatePacketSize", true);
// enable stream packet resend
Arena::SetNodeValue<bool>(pDevice->GetTLStreamNodeMap(), "StreamPacketResendEnable", true);
pDevice->StartStream();
Arena::IImage* pImage = pDevice->GetImage(2000);
std::cout << "Commence example\n\n";
SplitChannelsAndSaveImages(pImage, FILE_NAME);
std::cout << "\nExample complete\n";
// clean up example
pDevice->RequeueBuffer(pImage);
pDevice->StopStream();
pSystem->DestroyDevice(pDevice);
Arena::CloseSystem(pSystem);
}
catch (GenICam::GenericException& ge)
{
std::cout << "\nGenICam exception thrown: " << ge.what() << "\n";
exceptionThrown = true;
}
catch (std::exception& ex)
{
std::cout << "\nStandard exception thrown: " << ex.what() << "\n";
exceptionThrown = true;
}
catch (...)
{
std::cout << "\nUnexpected exception thrown\n";
exceptionThrown = true;
}
std::cout << "Press enter to complete\n";
std::cin.ignore();
std::getchar();
if (exceptionThrown)
return -1;
else
return 0;
}