-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
172 lines (143 loc) · 5.78 KB
/
main.cpp
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
#include <iostream>
#include <GalaxyIncludes.h>
#include <opencv2/opencv.hpp>
using namespace std;
cv::Mat img;
// User inherits the offline event processing class
class CSampleDeviceOfflineEventHandler : public IDeviceOfflineEventHandler
{
public:
void DoOnDeviceOfflineEvent(void* pUserParam)
{
cout << "Received device dropped event!" << endl;
}
};
// User inherits property update event processing class
class CSampleFeatureEventHandler : public IFeatureEventHandler
{
public:
void DoOnFeatureEvent(const GxIAPICPP::gxstring& strFeatureName, void* pUserParam)
{
cout << "Received the end of the exposure!" << endl;
}
};
// User inheritance collection event processing class
class CSampleCaptureEventHandler : public ICaptureEventHandler
{
public:
void DoOnImageCaptured(CImageDataPointer& objImageDataPointer, void* pUserParam)
{
cout << "Receive a frame of images!" << endl;
cout << "ImageInfo: " << objImageDataPointer->GetStatus() << endl;
cout << "ImageInfo: " << objImageDataPointer->GetWidth() << endl;
cout << "ImageInfo: " << objImageDataPointer->GetHeight() << endl;
cout << "ImageInfo: " << objImageDataPointer->GetPayloadSize() << endl;
img.create(objImageDataPointer->GetHeight(), objImageDataPointer->GetWidth(), CV_8UC3);
void* pRGB24Buffer = NULL;
// Assume that the original data is a BayerRG8 image
pRGB24Buffer = objImageDataPointer->ConvertToRGB24(GX_BIT_0_7, GX_RAW2RGB_NEIGHBOUR, true);
//pRGB24Buffer = objImageDataPointer->ConvertToRaw8(GX_BIT_0_7);//, GX_RAW2RGB_NEIGHBOUR, true);
memcpy(img.data, pRGB24Buffer, (objImageDataPointer->GetHeight()) * (objImageDataPointer->GetWidth())*3);
cv::flip(img, img, 0);
cv::imshow("sss", img);
cv::waitKey(1);
cout << "Number of frames:" << objImageDataPointer->GetFrameID() << endl;
}
};
int main(int argc, char* argv[])
{
// Declare the event callback object pointer
IDeviceOfflineEventHandler * pDeviceOfflineEventHandler = NULL;///< dropped event callback object
IFeatureEventHandler* pFeatureEventHandler = NULL;///<remote device event callback object
ICaptureEventHandler* pCaptureEventHandler = NULL;///< collection callback object
//initialization
IGXFactory::GetInstance().Init();
try
{
do
{
// enumeration equipment
gxdeviceinfo_vector vectorDeviceInfo;
IGXFactory::GetInstance().UpdateDeviceList(1000, vectorDeviceInfo);
if (0 == vectorDeviceInfo.size())
{
cout << "No equipment available!" << endl;
break;
}
cout << vectorDeviceInfo[0].GetVendorName() << endl;
cout << vectorDeviceInfo[0].GetSN() << endl;
// Open the first device and the first stream below the device
CGXDevicePointer ObjDevicePtr = IGXFactory::GetInstance().OpenDeviceBySN(
vectorDeviceInfo[0].GetSN(),
GX_ACCESS_EXCLUSIVE);
CGXStreamPointer ObjStreamPtr = ObjDevicePtr->OpenStream(0);
//Register device drop event [currently only Gigabit network cameras support this event notification]
GX_DEVICE_OFFLINE_CALLBACK_HANDLE hDeviceOffline = NULL;
pDeviceOfflineEventHandler = new CSampleDeviceOfflineEventHandler();
hDeviceOffline = ObjDevicePtr->RegisterDeviceOfflineCallback(pDeviceOfflineEventHandler, NULL);
// Get the remote device property controller
CGXFeatureControlPointer ObjFeatureControlPtr = ObjDevicePtr->GetRemoteFeatureControl();
// Set the exposure time(in the example, write dead us, just an example, does not represent the real working parameters)
//ObjFeatureControlPtr->GetFloatFeature("ExposureTime")->SetValue(50);
////Register remote device event: Exposure end event [At present, only Gigabit network cameras support exposure end events]
////Select event source
//ObjFeatureControlPtr->GetEnumFeature("EventSelector")->SetValue("ExposureEnd");
////Enable event
//ObjFeatureControlPtr->GetEnumFeature("EventNotification")->SetValue("On");
//GX_FEATURE_CALLBACK_HANDLE hFeatureEvent = NULL;
//pFeatureEventHandler = new CSampleFeatureEventHandler();
//hFeatureEvent = ObjFeatureControlPtr->RegisterFeatureCallback(
// "EventExposureEnd",
// pFeatureEventHandler,
// NULL);
// Registration callback collection
pCaptureEventHandler = new CSampleCaptureEventHandler();
ObjStreamPtr->RegisterCaptureCallback(pCaptureEventHandler, NULL);
//Send mining command
ObjStreamPtr->StartGrab();
ObjFeatureControlPtr->GetCommandFeature("AcquisitionStart")->Execute();
//At this point the mining is successful, the console prints the information until you enter any key to continue
getchar();
// Send stop command
ObjFeatureControlPtr->GetCommandFeature("AcquisitionStop")->Execute();
ObjStreamPtr->StopGrab();
// Logout collection callback
ObjStreamPtr->UnregisterCaptureCallback();
////Logout remote device event
//ObjFeatureControlPtr->UnregisterFeatureCallback(hFeatureEvent);
////Logout device dropped event
//ObjDevicePtr->UnregisterDeviceOfflineCallback(hDeviceOffline);
// Release resources
ObjStreamPtr->Close();
ObjDevicePtr->Close();
} while (0);
}
catch (CGalaxyException& e)
{
cout << "error code: " << e.GetErrorCode() << endl;
cout << "Error description:" << e.what() << endl;
}
catch (std::exception& e)
{
cout << "Error description:" << e.what() << endl;
}
// Initial initialization library
IGXFactory::GetInstance().Uninit();
// Destroy the event callback pointer
if (NULL != pCaptureEventHandler)
{
delete pCaptureEventHandler;
pCaptureEventHandler = NULL;
}
if (NULL != pDeviceOfflineEventHandler)
{
delete pDeviceOfflineEventHandler;
pDeviceOfflineEventHandler = NULL;
}
if (NULL != pFeatureEventHandler)
{
delete pFeatureEventHandler;
pFeatureEventHandler = NULL;
}
return 0;
}