Rev 4 | Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "CameraPointGrey.h"
#include <cstring>
void PrintError(FlyCapture2::Error error){
error.PrintErrorTrace();
}
vector<CameraInfo> CameraPointGrey::getCameraList(){
FlyCapture2::Error error;
FlyCapture2::BusManager busManager;
unsigned int numCameras;
error = busManager.GetNumOfCameras(&numCameras);
vector<CameraInfo> ret;
if (error != FlyCapture2::PGRERROR_OK){
PrintError(error);
return ret;
}
for (unsigned int i=0; i < numCameras; i++){
FlyCapture2::PGRGuid guid;
error = busManager.GetCameraFromIndex(i, &guid);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
// Connect to camera
FlyCapture2::Camera cam;
error = cam.Connect(&guid);
if (error != FlyCapture2::PGRERROR_OK)
PrintError( error );
// Get the camera information
FlyCapture2::CameraInfo camInfo;
error = cam.GetCameraInfo(&camInfo);
if (error != FlyCapture2::PGRERROR_OK)
PrintError( error );
CameraInfo camera;
camera.busID = camInfo.nodeNumber;
camera.model = camInfo.modelName;
camera.vendor = "Point Grey Research";
ret.push_back(camera);
}
return ret;
}
CameraPointGrey::CameraPointGrey(unsigned int camID){
FlyCapture2::Error error;
// Connect to camera
FlyCapture2::BusManager busManager;
FlyCapture2::PGRGuid camGuid;
busManager.GetCameraFromIndex(camID, &camGuid);
error = cam.Connect(&camGuid);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
// Configure software trigger
FlyCapture2::TriggerMode triggerMode;
triggerMode.onOff = true;
triggerMode.polarity = 0;
triggerMode.source = 7; // software
triggerMode.mode = 0;
error = cam.SetTriggerMode(&triggerMode);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
// Configure video mode and frame rate
FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_800x600Y8;
FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_30;
cam.SetVideoModeAndFrameRate(videoMode, frameRate);
// Get the camera information
FlyCapture2::CameraInfo camInfo;
error = cam.GetCameraInfo(&camInfo);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
std::cout << camInfo.vendorName << " " << camInfo.modelName << " " << camInfo.serialNumber << std::endl;
// Set reasonable default settings
CameraSettings settings;
settings.shutter = 33.33;
settings.gain = 0.0;
this->setCameraSettings(settings);
settings = this->getCameraSettings();
std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
// Start isochronous image transfer
error = cam.StartCapture();
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
return;
}
void CameraPointGrey::startCapture(){
FlyCapture2::Error error;
error = cam.StopCapture();
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
// Configure for hardware trigger
FlyCapture2::TriggerMode triggerMode;
triggerMode.onOff = true;
triggerMode.polarity = 0;
triggerMode.source = 0;
triggerMode.mode = 14;
error = cam.SetTriggerMode(&triggerMode);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
// Set the trigger timeout to 1000 ms
FlyCapture2::FC2Config config;
config.grabTimeout = 1000;
error = cam.SetConfiguration(&config);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
// error = cam.StartCapture();
// if (error != FlyCapture2::PGRERROR_OK)
// PrintError(error);
capturing = true;
}
void CameraPointGrey::stopCapture(){
capturing = false;
}
CameraFrame CameraPointGrey::lockFrame(){
FlyCapture2::Error error;
// Retrieve image
FlyCapture2::Image rawImage;
error = cam.RetrieveBuffer( &rawImage );
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
CameraFrame frame;
frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
frame.height = rawImage.GetCols();
frame.width = rawImage.GetRows();
frame.memory = rawImage.GetData();
return frame;
}
void CameraPointGrey::unlockFrame(){
}
CameraFrame CameraPointGrey::getSingleFrame(){
FlyCapture2::Error error;
// Fire software trigger
// broadcasting not supported on some platforms
cam.FireSoftwareTrigger(false);
// Retrieve the image
FlyCapture2::Image rawImage;
error = cam.RetrieveBuffer(&rawImage);
if (error != FlyCapture2::PGRERROR_OK)
PrintError(error);
CameraFrame frame;
frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
frame.height = rawImage.GetRows();
frame.width = rawImage.GetCols();
frame.memory = rawImage.GetData();
return frame;
}
size_t CameraPointGrey::getFrameSizeBytes(){
return 0;
}
void CameraPointGrey::getFrameWidthHeight(unsigned int *width, unsigned int *height){
// How do we poll this from the camera?
*width = 640;
*height = 480;
}
void CameraPointGrey::setCameraSettings(CameraSettings settings){
FlyCapture2::Property property;
property.onOff = true;
property.absControl = true;
property.type = FlyCapture2::SHUTTER;
property.absValue = settings.shutter;
cam.SetProperty(&property);
property.type = FlyCapture2::GAIN;
property.absValue = settings.gain;
cam.SetProperty(&property);
}
CameraSettings CameraPointGrey::getCameraSettings(){
FlyCapture2::Property property;
// Get settings:
CameraSettings settings;
property.type = FlyCapture2::SHUTTER;
cam.GetProperty(&property);
settings.shutter = property.absValue;
property.type = FlyCapture2::GAIN;
cam.GetProperty(&property);
settings.gain = property.absValue;
return settings;
}
CameraPointGrey::~CameraPointGrey(){
std::cout << "Deleting Point Grey Camera 1" << std::endl << std::flush;
// Stop camera transmission
// cam.StopCapture();
std::cout << "Deleting Point Grey Camera 2" << std::endl << std::flush;
// Gracefulle destruct the camera
// cam.Disconnect();
std::cout << "Deleting Point Grey Camera 3" << std::endl << std::flush;
}