forked from kamino410/cv-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
52 lines (42 loc) · 1.34 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
#include <opencv2/opencv.hpp>
#include <xiApi.h>
#define HandleResult(res, place) \
if (res != XI_OK) { \
printf("Error after %s (%d)\n", place, res); \
exit(1); \
}
int main() {
HANDLE xiH = NULL;
XI_RETURN stat = XI_OK;
// Allocate memory for ximea image
XI_IMG img;
memset(&img, 0, sizeof(img));
img.size = sizeof(XI_IMG);
// Connect to camera
stat = xiOpenDevice(0, &xiH);
HandleResult(stat, "xiOpenDevice");
// Configuration
stat = xiSetParamInt(xiH, XI_PRM_EXPOSURE, 100000);
HandleResult(stat, "xiGetParam (exposure)");
stat = xiSetParamFloat(xiH, XI_PRM_GAIN, 1);
HandleResult(stat, "xiGetParam (gain)");
stat = xiSetParamFloat(xiH, XI_PRM_GAMMAY, 1.0);
HandleResult(stat, "xiGetParam (gamma y)");
// Start acquisition
stat = xiStartAcquisition(xiH);
HandleResult(stat, "xiStartAcquisition");
// Preview output from camera
do {
// Get image from camera
stat = xiGetImage(xiH, 5000, &img);
HandleResult(stat, "xiGetImage");
// Convert XI_IMG into cv::Mat
cv::Mat cvimg(cv::Size((int)img.width, (int)img.height), CV_8UC1);
cvimg.data = (unsigned char*)img.bp;
// Show
cv::imshow("test", cvimg);
} while (cv::waitKey(1) == -1);
// Terminate
xiStopAcquisition(xiH);
xiCloseDevice(xiH);
}