diff --git a/CMakeLists.txt b/CMakeLists.txt index 740115d..fab6706 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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() diff --git a/README.md b/README.md index fc13821..0172075 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,9 @@ Before running FicTrac, you may configure your camera (frame rate, resolution, e PGR (FLIR) Spinnaker SDK 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 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 with the path to your vcpkg root directory): ``` -cmake -A x64 -D CMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake -D PGR_USB3=ON -D PGR_DIR="C:\path\to\Spinnaker" .. +cmake -A x64 -D CMAKE_TOOLCHAIN_FILE=/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. diff --git a/include/PGRSource.h b/include/PGRSource.h index d76311a..f3c4560 100644 --- a/include/PGRSource.h +++ b/include/PGRSource.h @@ -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 _cam; #endif // PGR_USB2/3 diff --git a/src/PGRSource.cpp b/src/PGRSource.cpp index 1fc6a30..4bd798c 100644 --- a/src/PGRSource.cpp +++ b/src/PGRSource.cpp @@ -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(); @@ -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); @@ -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);