Subversion Repositories seema-scanner

Rev

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

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