Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for using Spinnaker SDK 3.x.x.x #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

# optional build config
option(PGR_USB3 "Use Spinnaker SDK to capture from PGR USB3 cameras" OFF) # Disabled by default
option(SPINNAKER3 "Use Spinnaker SDK version 3" OFF) # Disabled by default
option(PGR_USB2 "Use FlyCapture SDK to capture from PGR USB2 cameras" OFF) # Disabled by default
option(BASLER_USB3 "Use Pylon SDK to capture from Basler USB3 cameras" OFF) # Disabled by default
if(PGR_USB3)
Expand Down Expand Up @@ -107,7 +108,7 @@ if(PGR_USB2 OR PGR_USB3)
if(PGR_USB2)
include_directories(${PGR_DIR}/include/flycapture) # for ubuntu default install dir
elseif(PGR_USB3)
include_directories(${PGR_DIR}/include/spinnaker) # for ubuntu default install dir
include_directories(${PGR_DIR}/include) # for ubuntu default install dir
endif()
endif()
elseif(BASLER_USB3)
Expand All @@ -132,6 +133,9 @@ if(PGR_USB2)
target_compile_definitions(fictrac_core PUBLIC PGR_USB2)
elseif(PGR_USB3)
target_compile_definitions(fictrac_core PUBLIC PGR_USB3)
if(SPINNAKER3)
target_compile_definitions(fictrac_core PUBLIC SPINNAKER3)
endif()
elseif(BASLER_USB3)
target_compile_definitions(fictrac_core PUBLIC BASLER_USB3)
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Before running FicTrac, you may configure your camera (frame rate, resolution, e
<summary>PGR (FLIR) Spinnaker SDK</summary>

1. Download and install the latest [Spinnaker SDK](https://www.flir.com/products/spinnaker-sdk/).
2. When preparing the build files for FicTrac using Cmake, you will need to specify to use Spinnaker using the switch `-D PGR_USB3=ON` and depending on where you installed the SDK, you may also need to provide the SDK directory path using the switch `-D PGR_DIR=...`. For example, for a Windows installation you would replace step 3 above with (replacing <vcpkg_root> with the path to your vcpkg root directory):
2. When preparing the build files for FicTrac using Cmake, you will need to specify to use Spinnaker using the switch `-D PGR_USB3=ON` and depending on where you installed the SDK, you may also need to provide the SDK directory path using the switch `-D PGR_DIR=...`. Furthermore, if the Spinnaker SDK you acquired is of version 3, you will need to use the switch `-D SPINNAKER3=true`. For example, for a Windows installation with Spinnaker SDK 3.X.X.X, you would replace step 3 above with (replacing <vcpkg_root> with the path to your vcpkg root directory):
```
cmake -A x64 -D CMAKE_TOOLCHAIN_FILE=<vcpkg root>/scripts/buildsystems/vcpkg.cmake -D PGR_USB3=ON -D PGR_DIR="C:\path\to\Spinnaker" ..
cmake -A x64 -D CMAKE_TOOLCHAIN_FILE=<vcpkg root>/scripts/buildsystems/vcpkg.cmake -D PGR_USB3=ON -D PGR_DIR="C:\path\to\Spinnaker" -D SPINNAKER3=true ..
```
3. Follow the other build steps as normal.

Expand Down
3 changes: 3 additions & 0 deletions include/PGRSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class PGRSource : public FrameSource {
Spinnaker::SystemPtr _system;
Spinnaker::CameraList _camList;
Spinnaker::CameraPtr _cam;
#if defined(SPINNAKER3)
Spinnaker::ImageProcessor _imgprocessor;
#endif // SPINNAKER3
#elif defined(PGR_USB2)
std::shared_ptr<FlyCapture2::Camera> _cam;
#endif // PGR_USB2/3
Expand Down
74 changes: 74 additions & 0 deletions src/PGRSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PGRSource::PGRSource(int index)
{
try {
#if defined(PGR_USB3)
#if defined(SPINNAKER3)
// Retrieve singleton reference to system object
_system = System::GetInstance();

Expand Down Expand Up @@ -87,6 +88,75 @@ PGRSource::PGRSource(int index)
_width = _cam->Width();
_height = _cam->Height();
_fps = getFPS();

// Initialize image processor
ImageProcessor _imgprocessor = ImageProcessor();
_imgprocessor.SetColorProcessing(ColorProcessingAlgorithm::SPINNAKER_COLOR_PROCESSING_ALGORITHM_NEAREST_NEIGHBOR);
#else
// Retrieve singleton reference to system object
_system = System::GetInstance();

// Print out current library version
const LibraryVersion spinnakerLibraryVersion = _system->GetLibraryVersion();
LOG("Opening PGR camera using Spinnaker SDK (version %d.%d.%d.%d)",
spinnakerLibraryVersion.major, spinnakerLibraryVersion.minor,
spinnakerLibraryVersion.type, spinnakerLibraryVersion.build);

// Retrieve list of cameras from the system
_camList = _system->GetCameras();

unsigned int numCameras = _camList.GetSize();

if (numCameras == 0) {
LOG_ERR("Error! Could not find any connected PGR cameras!");
return;
}
else {
LOG_DBG("Found %d PGR cameras. Connecting to camera %d..", numCameras, index);
}

// Select camera
_cam = _camList.GetByIndex(index);

// Initialize camera
_cam->Init();

// set acquisition mode - needed?
{
// Retrieve GenICam nodemap
Spinnaker::GenApi::INodeMap& nodeMap = _cam->GetNodeMap();

// Retrieve enumeration node from nodemap
Spinnaker::GenApi::CEnumerationPtr ptrAcquisitionMode = nodeMap.GetNode("AcquisitionMode");
if (!IsAvailable(ptrAcquisitionMode) || !IsWritable(ptrAcquisitionMode)) {
LOG_ERR("Unable to set acquisition mode to continuous (enum retrieval)!");
return;
}

// Retrieve entry node from enumeration node
Spinnaker::GenApi::CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName("Continuous");
if (!IsAvailable(ptrAcquisitionModeContinuous) || !IsReadable(ptrAcquisitionModeContinuous)) {
LOG_ERR("Unable to set acquisition mode to continuous (entry retrieval)!");
return;
}

// 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);

LOG_DBG("Acquisition mode set to continuous.");
}

// Begin acquiring images
_cam->BeginAcquisition();

// Get some params
_width = _cam->Width();
_height = _cam->Height();
_fps = getFPS();
#endif
#elif defined(PGR_USB2)
LOG_DBG("Looking for camera at index %d...", index);

Expand Down Expand Up @@ -269,7 +339,11 @@ bool PGRSource::grab(cv::Mat& frame)

try {
// Convert image
#if defined(SPINNAKER3)
ImagePtr bgr_image = _imgprocessor.Convert(pgr_image, PixelFormat_BGR8);
#else
ImagePtr bgr_image = pgr_image->Convert(PixelFormat_BGR8, NEAREST_NEIGHBOR);
#endif

Mat tmp(_height, _width, CV_8UC3, bgr_image->GetData(), bgr_image->GetStride());
tmp.copyTo(frame);
Expand Down