-
Notifications
You must be signed in to change notification settings - Fork 2
/
methods.cxx
138 lines (113 loc) · 3.84 KB
/
methods.cxx
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
#include <methods.hpp>
gige::IDevice setup(void) {
// number of images to be allocated in buffer
UINT32 numImages = 10;
// allocate image buffer
UINT8** buffer = new UINT8*[numImages];
if (buffer != NULL) {
for (UINT32 i = 0; i < numImages; ++i) {
buffer[i] = NULL;
}
}
gige::InitGigEVisionAPI();
gige::IGigEVisionAPI gigeApi = gige::GetGigEVisionAPI();
if (!gigeApi->IsUsingKernelDriver()) {
std::cout << "Warning: Smartek Filter Driver not loaded." << std::endl;
}
gigeApi->SetHeartbeatTime(3);
// gige_IGigEVisionAPI_RegisterCallback(gigeApi, gige_ICallbackEvent_Handler);
// discover all devices on network
gigeApi->FindAllDevices(3.0);
const gige::DevicesList devices = gigeApi->GetAllDevices();
if (devices.size() > 0 && buffer != NULL) {
// take first device in list
gige::IDevice device = devices[0];
if (device != NULL && device->Connect()) {
std::string text;
INT64 int64Value;
std::cout << "Connected to first camera: " << Common::IpAddrToString(device->GetIpAddress()) << std::endl;
if (device->GetStringNodeValue("DeviceVendorName", text)) {
std::cout << "Device Vendor: " << text << std::endl;
}
if (device->GetStringNodeValue("DeviceModelName", text)) {
std::cout << "Device Model: " << text << std::endl;
}
if (device->GetIntegerNodeValue("Width", int64Value)) {
std::cout << "Width: " << (int)int64Value << std::endl;
}
if (device->GetIntegerNodeValue("Height", int64Value)) {
std::cout << "Height: " << (int)int64Value << std::endl;
}
INT64 packetSize = 0;
device->GetIntegerNodeValue("GevSCPSPacketSize", packetSize);
packetSize = packetSize & 0xFFFF;
std::cout << "PacketSize: " << (int)packetSize << std::endl;
// reset image queue to zero
device->ResetImageQueue();
// allocate user image queue and prepare for image buffer
device->InitUserImageQueue(numImages);
// get image size from camera
INT64 payloadSize;
device->GetIntegerNodeValue("PayloadSize", payloadSize);
for (UINT32 i = 0; i < numImages; ++i) {
// allocate memory for image
buffer[i] = new UINT8[payloadSize];
// add memory to image queue
if (buffer[i] != NULL)
device->AddToUserImageQueue(buffer[i], payloadSize);
}
// disable trigger mode
bool status = device->SetStringNodeValue("TriggerMode", "Off");
// set continuous acquisition mode
status = device->SetStringNodeValue("AcquisitionMode", "Continuous");
// start acquisition
status = device->SetIntegerNodeValue("TLParamsLocked", 1);
status = device->CommandNodeExecute("AcquisitionStart");
std::cout << "Acquisition Start, press any key to exit loop..." << std::endl;
//return device;
return device;
}
else {
std::cout << "Warning:Could not connect to device!" << std::endl;
return NULL;
}
}
else {
std::cout << "Warning: No devices found!" << std::endl;
return NULL;
}
}
Frame getFrame(gige::IDevice device, float timeout) {
// wait for image for 3 seconds
Frame frame;
if (device->WaitForImage(timeout)) {
// grab one image
gige::IImageInfo imageInfo;
device->GetImageInfo(&imageInfo);
if (imageInfo != NULL) {
UINT32 sizeX, sizeY;
imageInfo->GetSize(sizeX, sizeY);
int size = imageInfo->GetRawDataSize();
UINT8* buffer = new UINT8[size];
std::memcpy(imageInfo->GetRawData(), buffer, size);
frame.data = buffer;
bool result = imageInfo->GetSize(frame.x, frame.y);
if(!result) {
std::cout << "Failed to acquire image size" << std::endl;
}
}
// remove (pop) image from image buffer
device->PopImage(imageInfo);
}
else {
std::cout << "No image acquired..." << std::endl;
}
return frame;
}
void clearBuffer(UINT8* buffer) {
delete [] buffer;
}
void close(gige::IDevice device) {
device->Disconnect();
std::cout << "Disconnected from " << Common::IpAddrToString(device->GetIpAddress()) << std::endl;
}