Subversion Repositories seema-scanner

Rev

Rev 17 | Rev 19 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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