Subversion Repositories seema-scanner

Rev

Rev 4 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jakw 1
#include "CameraPointGrey.h"
2
#include <cstring>
3
 
4
void PrintError(FlyCapture2::Error error){
5
    error.PrintErrorTrace();
6
}
7
 
8
vector<CameraInfo> CameraPointGrey::getCameraList(){
9
 
10
    FlyCapture2::Error error;
11
 
12
    FlyCapture2::BusManager busManager;
13
    unsigned int numCameras;
14
    error = busManager.GetNumOfCameras(&numCameras);
15
 
16
    vector<CameraInfo> ret;
17
 
18
    if (error != FlyCapture2::PGRERROR_OK){
19
        PrintError(error);
20
        return ret;
21
    }
22
 
23
    for (unsigned int i=0; i < numCameras; i++){
24
        FlyCapture2::PGRGuid guid;
25
        error = busManager.GetCameraFromIndex(i, &guid);
26
        if (error != FlyCapture2::PGRERROR_OK)
27
            PrintError(error);
28
 
29
        // Connect to camera
30
        FlyCapture2::Camera cam;
31
        error = cam.Connect(&guid);
32
        if (error != FlyCapture2::PGRERROR_OK)
33
            PrintError( error );
34
 
35
        // Get the camera information
36
        FlyCapture2::CameraInfo camInfo;
37
        error = cam.GetCameraInfo(&camInfo);
38
        if (error != FlyCapture2::PGRERROR_OK)
39
            PrintError( error );
40
 
41
        CameraInfo camera;
42
        camera.busID = camInfo.nodeNumber;
43
        camera.model = camInfo.modelName;
44
        camera.vendor = "Point Grey Research";
45
 
46
        ret.push_back(camera);
47
    }
48
 
49
    return ret;
50
}
51
 
52
CameraPointGrey::CameraPointGrey(unsigned int camID){
53
 
54
    FlyCapture2::Error error;
55
 
56
    // Connect to camera
57
    FlyCapture2::BusManager busManager;
58
    FlyCapture2::PGRGuid camGuid;
59
    busManager.GetCameraFromIndex(camID, &camGuid);
60
    error = cam.Connect(&camGuid);
61
    if (error != FlyCapture2::PGRERROR_OK)
62
        PrintError(error);
63
 
64
    // Configure software trigger
65
    FlyCapture2::TriggerMode triggerMode;
66
    triggerMode.onOff = true;
67
    triggerMode.polarity = 0;
68
    triggerMode.source = 7; // software
69
    triggerMode.mode = 0;
70
    error = cam.SetTriggerMode(&triggerMode);
71
    if (error != FlyCapture2::PGRERROR_OK)
72
        PrintError(error);
73
 
74
    // Get the camera information
75
    FlyCapture2::CameraInfo camInfo;
76
    error = cam.GetCameraInfo(&camInfo);
77
    if (error != FlyCapture2::PGRERROR_OK)
78
        PrintError(error);
79
 
80
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << std::endl;
81
 
82
    // Set reasonable default settings
83
    CameraSettings settings;
84
    settings.shutter = 8.33;
85
    //settings.shutter = 16.66;
86
    settings.gain = 0.0;
87
    this->setCameraSettings(settings);
88
 
89
    settings = this->getCameraSettings();
90
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
91
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
92
 
93
    // Start isochronous image transfer
94
    error = cam.StartCapture();
95
    if (error != FlyCapture2::PGRERROR_OK)
96
        PrintError(error);
97
 
98
    return;
99
}
100
 
101
void CameraPointGrey::startCapture(){
102
 
103
    FlyCapture2::Error error;
104
 
105
    error = cam.StopCapture();
106
    if (error != FlyCapture2::PGRERROR_OK)
107
        PrintError(error);
108
 
109
    // Configure for hardware trigger
110
    FlyCapture2::TriggerMode triggerMode;
111
    triggerMode.onOff = true;
112
    triggerMode.polarity = 0;
113
    triggerMode.source = 0;
114
    triggerMode.mode = 14;
115
    error = cam.SetTriggerMode(&triggerMode);
116
    if (error != FlyCapture2::PGRERROR_OK)
117
        PrintError(error);
118
 
119
    // Set the trigger timeout to 1000 ms
120
    FlyCapture2::FC2Config config;
121
    config.grabTimeout = 1000;
122
    error = cam.SetConfiguration(&config);
123
    if (error != FlyCapture2::PGRERROR_OK)
124
        PrintError(error);
125
 
126
    error = cam.StartCapture();
127
    if (error != FlyCapture2::PGRERROR_OK)
128
        PrintError(error);
129
 
130
    capturing = true;
131
}
132
 
133
void CameraPointGrey::stopCapture(){
134
 
135
    capturing = false;
136
}
137
 
138
CameraFrame CameraPointGrey::lockFrame(){
139
 
140
    FlyCapture2::Error error;
141
 
142
    // Retrieve image
143
    FlyCapture2::Image rawImage;
144
    error = cam.RetrieveBuffer( &rawImage );
145
    if (error != FlyCapture2::PGRERROR_OK)
146
        PrintError(error);
147
 
148
    CameraFrame frame;
149
 
150
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
151
    frame.height = rawImage.GetCols();
152
    frame.width = rawImage.GetRows();
153
    frame.memory = rawImage.GetData();
154
 
155
    return frame;
156
}
157
 
158
void CameraPointGrey::unlockFrame(){
159
 
160
}
161
 
162
 
163
CameraFrame CameraPointGrey::getSingleFrame(){
164
 
165
    FlyCapture2::Error error;
166
 
167
    // Fire software trigger
168
    cam.FireSoftwareTrigger(true);
169
 
170
    // Retrieve the image
171
    FlyCapture2::Image rawImage;
172
    error = cam.RetrieveBuffer(&rawImage);
173
    if (error != FlyCapture2::PGRERROR_OK)
174
        PrintError(error);
175
 
176
    CameraFrame frame;
177
 
178
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
179
    frame.height = rawImage.GetRows();
180
    frame.width = rawImage.GetCols();
181
    frame.memory = rawImage.GetData();
182
 
183
    return frame;
184
}
185
 
186
 
187
size_t CameraPointGrey::getFrameSizeBytes(){
188
 
189
 
190
    return 0;
191
}
192
 
193
void CameraPointGrey::getFrameWidthHeight(unsigned int *width, unsigned int *height){
194
    // How do we poll this from the camera?
195
    *width = 640;
196
    *height = 480;
197
 
198
}
199
 
200
 
201
void CameraPointGrey::setCameraSettings(CameraSettings settings){
202
 
203
    FlyCapture2::Property property;
204
    property.onOff = true;
205
    property.absControl = true;
206
 
207
    property.type = FlyCapture2::SHUTTER;
208
    property.absValue = settings.shutter;
209
    cam.SetProperty(&property);
210
 
211
    property.type = FlyCapture2::GAIN;
212
    property.absValue = settings.gain;
213
    cam.SetProperty(&property);
214
 
215
}
216
 
217
CameraSettings CameraPointGrey::getCameraSettings(){
218
 
219
    FlyCapture2::Property property;
220
 
221
	// Get settings:
222
    CameraSettings settings;
223
 
224
    property.type = FlyCapture2::SHUTTER;
225
    cam.GetProperty(&property);
226
    settings.shutter = property.absValue;
227
 
228
    property.type = FlyCapture2::GAIN;
229
    cam.GetProperty(&property);
230
    settings.gain = property.absValue;
231
 
232
    return settings;
233
}
234
 
235
CameraPointGrey::~CameraPointGrey(){
236
 
237
    std::cout << "Deleting Point Grey Camera 1" << std::endl << std::flush;
238
 
239
    // Stop camera transmission
240
    cam.StopCapture();
241
 
242
    std::cout << "Deleting Point Grey Camera 2" << std::endl << std::flush;
243
 
244
    // Gracefulle destruct the camera
245
    cam.Disconnect();
246
 
247
    std::cout << "Deleting Point Grey Camera 3" << std::endl << std::flush;
248
}
249
 
250
 
251