Subversion Repositories seema-scanner

Rev

Rev 1 | Rev 17 | Go to most recent revision | Details | Compare with Previous | 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
 
4 jakw 74
    // Configure video mode and frame rate
75
    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_640x480Y8;
76
    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_15;
77
    cam.SetVideoModeAndFrameRate(videoMode, frameRate);
78
 
1 jakw 79
    // Get the camera information
80
    FlyCapture2::CameraInfo camInfo;
81
    error = cam.GetCameraInfo(&camInfo);
82
    if (error != FlyCapture2::PGRERROR_OK)
83
        PrintError(error);
84
 
4 jakw 85
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << "  " << camInfo.serialNumber << std::endl;
1 jakw 86
 
87
    // Set reasonable default settings
88
    CameraSettings settings;
4 jakw 89
    settings.shutter = 33.33;
1 jakw 90
    settings.gain = 0.0;
91
    this->setCameraSettings(settings);
92
 
93
    settings = this->getCameraSettings();
94
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
95
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
96
 
97
    // Start isochronous image transfer
98
    error = cam.StartCapture();
99
    if (error != FlyCapture2::PGRERROR_OK)
100
        PrintError(error);
101
 
102
    return;
103
}
104
 
105
void CameraPointGrey::startCapture(){
106
 
107
    FlyCapture2::Error error;
108
 
109
    error = cam.StopCapture();
110
    if (error != FlyCapture2::PGRERROR_OK)
111
        PrintError(error);
112
 
113
    // Configure for hardware trigger
114
    FlyCapture2::TriggerMode triggerMode;
115
    triggerMode.onOff = true;
116
    triggerMode.polarity = 0;
117
    triggerMode.source = 0;
118
    triggerMode.mode = 14;
119
    error = cam.SetTriggerMode(&triggerMode);
120
    if (error != FlyCapture2::PGRERROR_OK)
121
        PrintError(error);
122
 
123
    // Set the trigger timeout to 1000 ms
124
    FlyCapture2::FC2Config config;
125
    config.grabTimeout = 1000;
126
    error = cam.SetConfiguration(&config);
127
    if (error != FlyCapture2::PGRERROR_OK)
128
        PrintError(error);
129
 
4 jakw 130
//    error = cam.StartCapture();
131
//    if (error != FlyCapture2::PGRERROR_OK)
132
//        PrintError(error);
1 jakw 133
 
134
    capturing = true;
135
}
136
 
137
void CameraPointGrey::stopCapture(){
138
 
139
    capturing = false;
140
}
141
 
142
CameraFrame CameraPointGrey::lockFrame(){
143
 
144
    FlyCapture2::Error error;
145
 
146
    // Retrieve image
147
    FlyCapture2::Image rawImage;
148
    error = cam.RetrieveBuffer( &rawImage );
149
    if (error != FlyCapture2::PGRERROR_OK)
150
        PrintError(error);
151
 
152
    CameraFrame frame;
153
 
154
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
155
    frame.height = rawImage.GetCols();
156
    frame.width = rawImage.GetRows();
157
    frame.memory = rawImage.GetData();
158
 
159
    return frame;
160
}
161
 
162
void CameraPointGrey::unlockFrame(){
163
 
164
}
165
 
166
 
167
CameraFrame CameraPointGrey::getSingleFrame(){
168
 
169
    FlyCapture2::Error error;
170
 
171
    // Fire software trigger
4 jakw 172
    // broadcasting not supported on some platforms
173
    cam.FireSoftwareTrigger(false);
1 jakw 174
 
175
    // Retrieve the image
176
    FlyCapture2::Image rawImage;
177
    error = cam.RetrieveBuffer(&rawImage);
178
    if (error != FlyCapture2::PGRERROR_OK)
179
        PrintError(error);
180
 
181
    CameraFrame frame;
182
 
183
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
184
    frame.height = rawImage.GetRows();
185
    frame.width = rawImage.GetCols();
186
    frame.memory = rawImage.GetData();
187
 
188
    return frame;
189
}
190
 
191
 
192
size_t CameraPointGrey::getFrameSizeBytes(){
193
 
194
 
195
    return 0;
196
}
197
 
198
void CameraPointGrey::getFrameWidthHeight(unsigned int *width, unsigned int *height){
199
    // How do we poll this from the camera?
200
    *width = 640;
201
    *height = 480;
202
 
203
}
204
 
205
 
206
void CameraPointGrey::setCameraSettings(CameraSettings settings){
207
 
208
    FlyCapture2::Property property;
209
    property.onOff = true;
210
    property.absControl = true;
211
 
212
    property.type = FlyCapture2::SHUTTER;
213
    property.absValue = settings.shutter;
214
    cam.SetProperty(&property);
215
 
216
    property.type = FlyCapture2::GAIN;
217
    property.absValue = settings.gain;
218
    cam.SetProperty(&property);
219
 
220
}
221
 
222
CameraSettings CameraPointGrey::getCameraSettings(){
223
 
224
    FlyCapture2::Property property;
225
 
226
	// Get settings:
227
    CameraSettings settings;
228
 
229
    property.type = FlyCapture2::SHUTTER;
230
    cam.GetProperty(&property);
231
    settings.shutter = property.absValue;
232
 
233
    property.type = FlyCapture2::GAIN;
234
    cam.GetProperty(&property);
235
    settings.gain = property.absValue;
236
 
237
    return settings;
238
}
239
 
240
CameraPointGrey::~CameraPointGrey(){
241
    std::cout << "Deleting Point Grey Camera 1" << std::endl << std::flush;
242
 
243
    // Stop camera transmission
4 jakw 244
   // cam.StopCapture();
1 jakw 245
 
246
    std::cout << "Deleting Point Grey Camera 2" << std::endl << std::flush;
247
 
248
    // Gracefulle destruct the camera
4 jakw 249
   // cam.Disconnect();
1 jakw 250
 
251
    std::cout << "Deleting Point Grey Camera 3" << std::endl << std::flush;
252
}
253
 
254
 
255