forked from charlie-x/PTAM-Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoSource_Win32_CMU1394.cpp
176 lines (134 loc) · 4.08 KB
/
VideoSource_Win32_CMU1394.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
173
174
175
176
// Copyright 2010 Isis Innovation Limited
// This video source uses Point Grey's FlyCapture 2 API
// It is based on their example code
// Parameters are hard-coded here - adapt to your specific camera.
#pragma comment(lib,"FlyCapture2_v110.lib")
#include "VideoSource.h"
#include <gvars3/instances.h>
#include <cvd/utility.h>
#define WIN32_MEAN_AND_LEAN
#include <windows.h>
#include "FlyCapture2.h"
using namespace std;
using namespace CVD;
using namespace GVars3;
using namespace FlyCapture2;
int IMAGE_W = (2048);
int IMAGE_H = (2048);
static Camera cam;
static void PrintErrorAndExit(Error error)
{
error.PrintErrorTrace();
exit(0);
}
VideoSource::VideoSource(): m_buffer(NULL)
{
Error error;
BusManager busMgr;
unsigned int numCameras;
error = busMgr.GetNumOfCameras(&numCameras);
if (error != PGRERROR_OK) PrintErrorAndExit(error);
printf("Number of cameras detected: %u\n", numCameras);
assert(numCameras > 0);
PGRGuid guid;
error = busMgr.GetCameraFromIndex(0, &guid);
if (error != PGRERROR_OK) PrintErrorAndExit(error);
error = cam.Connect(&guid);
if (error != PGRERROR_OK) PrintErrorAndExit(error);
CameraInfo camInfo;
error = cam.GetCameraInfo(&camInfo);
if (error != PGRERROR_OK) PrintErrorAndExit(error);
printf(
"\n*** CAMERA INFORMATION ***\n"
"Serial number - %u\n"
"Camera model - %s\n"
"Camera vendor - %s\n"
"Sensor - %s\n"
"Resolution - %s\n"
"Firmware version - %s\n"
"Firmware build time - %s\n\n",
camInfo.serialNumber,
camInfo.modelName,
camInfo.vendorName,
camInfo.sensorInfo,
camInfo.sensorResolution,
camInfo.firmwareVersion,
camInfo.firmwareBuildTime);
VideoMode vm;
FrameRate fr;
// Start capturing images at 640x480xY8
// You probably need to change this stuff for your camera
mirSize = ImageRef(IMAGE_W, IMAGE_H);
bool bStatus;
int i,x;
for (i = VIDEOMODE_160x120YUV444; i < NUM_VIDEOMODES-1; i++) {
for (x = FRAMERATE_1_875; x < NUM_FRAMERATES-1; x++) {
error = cam.GetVideoModeAndFrameRateInfo((VideoMode)i, (FrameRate)x, &bStatus);
if (error != PGRERROR_OK)
{
PrintErrorAndExit(error);
}
if (bStatus == TRUE)
{
printf("found at %d %d\n", i, x);
break;
}
}
}
error = cam.SetVideoModeAndFrameRate(VIDEOMODE_640x480RGB, FRAMERATE_120);
if (error != PGRERROR_OK)
{
// my PT camera doesnt support these mode changes.
// PrintErrorAndExit(error);
}
cam.GetVideoModeAndFrameRate(&vm, &fr);
error = cam.StartCapture();
if (error != PGRERROR_OK) PrintErrorAndExit(error);
};
void VideoSource::GetAndFillFrameBWandRGB(CVD::Image<CVD::byte> &imBW, CVD::Image<CVD::Rgb<CVD::byte> > &imRGB)
{
Error error;
imRGB.resize(mirSize);
imBW.resize(mirSize);
static FlyCapture2::Image imCap;
error = cam.RetrieveBuffer(&imCap);
if (error != PGRERROR_OK)
{
PrintErrorAndExit(error);
}
unsigned char *pImage = imCap.GetData();
for (int y = 0; y<mirSize.y; y++) {
for (int x = 0; x<mirSize.x; x++) {
imRGB[y][x].blue = *pImage;
pImage++;
imRGB[y][x].green =*pImage;
imBW[y][x] = *pImage;
pImage++;
imRGB[y][x].red = *pImage;
pImage++;
}
}
}
ImageRef VideoSource::Size()
{
return mirSize;
}
VideoSource::~VideoSource()
{
Error error;
delete[] m_buffer;
// Stop capturing images
error = cam.StopCapture();
if (error != PGRERROR_OK)
{
PrintErrorAndExit(error);
return ;
}
// Disconnect the camera
error = cam.Disconnect();
if (error != PGRERROR_OK)
{
PrintErrorAndExit(error);
return;
}
}