Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "SpinnakerCapture.h"
SpinnakerCapture::SpinnakerCapture(QObject *parent)
{
// Retrieve singleton reference to system object
system = System::GetInstance();
// Retrieve list of cameras from the system
camList = system->GetCameras();
unsigned int numCameras = camList.GetSize();
qDebug() << "Number of cameras detected: " << numCameras;
// Finish ifthere are no cameras
if(numCameras == 0){
// Clear camera list before releasing system
camList.Clear();
// Release system
system->ReleaseInstance();
qDebug() << "Not enough cameras!" ;
qDebug() << "Done! Press Enter to exit..." ;
getchar();
qDebug()<<"BAD";
}
pCam = NULL;
pCam = camList.GetByIndex(0);
try{
// Retrieve TL device nodemap and print device information
nodeMapTLDevice = &pCam->GetTLDeviceNodeMap();
// Initialize camera
pCam->Init();
// Retrieve GenICam nodemap
nodeMap = &pCam->GetNodeMap();
width = pCam->Width.GetValue();
height = pCam->Height.GetValue();
exposureTime = pCam->ExposureTime.GetValue();
pixelFormat = pCam->PixelFormat.GetValue();
qDebug() <<"Initialized Spinnaker compatible camera ("
<< width << "x" << height
<< pCam->PixelFormat.GetCurrentEntry()->GetSymbolic()
<< ")";
isInitialized = true;
}
catch (Spinnaker::Exception &e){
qDebug() << "Error: " << e.what() ;
}
}
// This function configures a custom exposure time. Automatic exposure is turned
// off in order to allow for the customization, and then the custom setting is
// applied.
int SpinnakerCapture::configureExposure(double exposureTimeToSet)
{
int result = 0;
qDebug() << "*** CONFIGURING EXPOSURE ***";
try{
//
// Turn off automatic exposure mode
//
// *** NOTES ***
// Automatic exposure prevents the manual configuration of exposure
// time and needs to be turned off.
//
// *** LATER ***
// Exposure time can be set automatically or manually as needed. This
// example turns automatic exposure off to set it manually and back
// on in order to return the camera to its default state.
//
CEnumerationPtr ptrExposureAuto = nodeMap->GetNode("ExposureAuto");
if(!IsAvailable(ptrExposureAuto) || !IsWritable(ptrExposureAuto)){
qDebug() << "Unable to disable automatic exposure (node retrieval). Aborting...";
return -1;
}
CEnumEntryPtr ptrExposureAutoOff = ptrExposureAuto->GetEntryByName("Off");
if(!IsAvailable(ptrExposureAutoOff) || !IsReadable(ptrExposureAutoOff)){
qDebug() << "Unable to disable automatic exposure (enum entry retrieval). Aborting...";
return -1;
}
ptrExposureAuto->SetIntValue(ptrExposureAutoOff->GetValue());
qDebug() << "Automatic exposure disabled...";
//
// Set exposure time manually; exposure time recorded in microseconds
//
// *** NOTES ***
// The node is checked for availability and writability prior to the
// setting of the node. Further, it is ensured that the desired exposure
// time does not exceed the maximum. Exposure time is counted in
// microseconds. This information can be found out either by
// retrieving the unit with the GetUnit() method or by checking SpinView.
//
CFloatPtr ptrExposureTime = nodeMap->GetNode("ExposureTime");
if(!IsAvailable(ptrExposureTime) || !IsWritable(ptrExposureTime)){
qDebug() << "Unable to set exposure time. Aborting...";
return -1;
}
// Ensure desired exposure time does not exceed the maximum
const double exposureTimeMax = ptrExposureTime->GetMax();
if(exposureTimeToSet > exposureTimeMax){
exposureTimeToSet = exposureTimeMax;
}
exposureTime = exposureTimeToSet;
ptrExposureTime->SetValue(exposureTimeToSet);
qDebug() << "Exposure time set to " << exposureTimeToSet << " us...";
}
catch(Spinnaker::Exception &e){
qDebug() << "Error: " << e.what() ;
result = -1;
}
return result;
}
// This function acquires images from a device.
int SpinnakerCapture::acquireImages(unsigned int nImagesToCapture)
{
int result = 0;
qDebug() << "*** IMAGE ACQUISITION ***";
try{
// Set acquisition mode to continuous
// Retrieve enumeration node from nodemap
CEnumerationPtr ptrAcquisitionMode = nodeMap->GetNode("AcquisitionMode");
if(!IsAvailable(ptrAcquisitionMode) || !IsWritable(ptrAcquisitionMode)){
qDebug() << "Unable to set acquisition mode to continuous (enum retrieval). Aborting...";
return -1;
}
// Retrieve entry node from enumeration node
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName("Continuous");
if(!IsAvailable(ptrAcquisitionModeContinuous) || !IsReadable(ptrAcquisitionModeContinuous)){
qDebug() << "Unable to set acquisition mode to continuous (entry retrieval). Aborting...";
return -1;
}
// Retrieve integer value from entry node
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
// Set integer value from entry node as new value of enumeration node
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
pCam->BeginAcquisition();
// Retrieve, convert, and emit images
for (unsigned int imageCnt = 0; imageCnt < nImagesToCapture; imageCnt++){
try{
ImagePtr pResultImage = pCam->GetNextImage();
if(pResultImage->IsIncomplete()){
qDebug() << "Image incomplete with image status " << pResultImage->GetImageStatus() << "...";
}else{
//
// Print image information; height and width recorded in pixels
//
// *** NOTES ***
// Images have quite a bit of available metadata including
// things such as CRC, image status, and offset values, to
// name a few.
//
int cvFormat;
ImagePtr convertedImage;
switch(pixelFormat){
case PixelFormat_BGR8:
//we could also convert the format:
//convertedImage = pResultImage->Convert(Spinnaker::PixelFormatEnums(pixelFormat), NEAREST_NEIGHBOR);
convertedImage = pResultImage;
cvFormat = CV_8UC3;
break;
case PixelFormat_Mono8:
convertedImage = pResultImage;
cvFormat = CV_8UC1;
break;
case PixelFormat_Mono16:
convertedImage = pResultImage;
cvFormat = CV_16UC1;
break;
default:
convertedImage = pResultImage;
cvFormat = CV_8UC3;
}
unsigned int XPadding = convertedImage->GetXPadding();
unsigned int YPadding = convertedImage->GetYPadding();
unsigned int rowsize = convertedImage->GetWidth();
unsigned int colsize = convertedImage->GetHeight();
//image data contains padding. When allocating Mat container size, you need to account for the X,Y image data padding.
cv::Mat cvMat = cv::Mat(colsize + YPadding, rowsize + XPadding, cvFormat, convertedImage->GetData(), convertedImage->GetStride());
emit(sendFrame(cvMat.clone()));
}
// Images retrieved directly from the camera (i.e. non-converted
// images) need to be released in order to keep from filling the
// buffer.
pResultImage->Release();
}catch (Spinnaker::Exception &e){
qDebug() << "Error: " << e.what() ;
result = -1;
}
}
//
// End acquisition
//
// *** NOTES ***
// Ending acquisition appropriately helps ensure that devices clean up
// properly and do not need to be power-cycled to maintain integrity.
//
pCam->EndAcquisition();
}
catch (Spinnaker::Exception &e){
qDebug() << "Error: " << e.what() ;
result = -1;
}
return result;
}
// This function prints the device information of the camera from the transport
// layer; please see NodeMapInfo example for more in-depth comments on printing
// device information from the nodemap.
int SpinnakerCapture::printDeviceInfo()
{
int result = 0;
qDebug() << "*** DEVICE INFORMATION ***";
try{
FeatureList_t features;
CCategoryPtr category = nodeMap->GetNode("DeviceInformation");
if(IsAvailable(category) && IsReadable(category)){
category->GetFeatures(features);
FeatureList_t::const_iterator it;
for (it = features.begin(); it != features.end(); ++it){
CNodePtr pfeatureNode = *it;
qDebug() << pfeatureNode->GetName() << " : ";
CValuePtr pValue = (CValuePtr)pfeatureNode;
qDebug() << (IsReadable(pValue) ? pValue->ToString() : "Node not readable");
}
}
else{
qDebug() << "Device control information not available.";
}
}
catch (Spinnaker::Exception &e){
qDebug() << "Error: " << e.what() ;
result = -1;
}
return result;
}
SpinnakerCapture::~SpinnakerCapture()
{
// Deinitialize camera
pCam->DeInit();
pCam = NULL;
nodeMapTLDevice = NULL;
nodeMap = NULL;
// Clear camera list before releasing system
camList.Clear();
// Release system
system->ReleaseInstance();
}